Skip to content
Snippets Groups Projects
Commit bfbb0aae authored by Yogmatee Roochun's avatar Yogmatee Roochun
Browse files

removed debugging logs from OrcidClaiming

parent 69e2540d
No related branches found
No related tags found
3 merge requests!380Pipeline changes,!379Build step added for the master branch,!378k8s release
/* global thorApplicationNamespace */ /* global thorApplicationNamespace */
/* eslint-disable */
import React from 'react' import React from 'react'
import styled from 'styled-components' import styled from 'styled-components'
...@@ -51,9 +50,6 @@ const DefaultShowComponent = ({ onClick, isLoading }) => ( ...@@ -51,9 +50,6 @@ const DefaultShowComponent = ({ onClick, isLoading }) => (
</Button> </Button>
) )
// Load THOr script in your front-end under a <script> tag.
// This script provides you with a global variable called "thorApplicationNamespace" that will allow you to access all the API functions, constants and data attributes.
const loadScript = ( const loadScript = (
className, className,
url, url,
...@@ -64,7 +60,7 @@ const loadScript = ( ...@@ -64,7 +60,7 @@ const loadScript = (
script.classList.add(className) script.classList.add(className)
script.src = url script.src = url
script.async = isAsync script.async = isAsync
script.onload = scriptLoaded // When your application loads for the first time, you must initialize THOR calling thorApplicationNamespace.loadClaimingInfo() script.onload = scriptLoaded
document.body.appendChild(script) document.body.appendChild(script)
} }
...@@ -80,44 +76,28 @@ class OrcidClaim extends React.Component { ...@@ -80,44 +76,28 @@ class OrcidClaim extends React.Component {
claimed: false, claimed: false,
userData: null, userData: null,
} }
// Load THOr script in your front-end under a <script> tag.
if (document.getElementsByClassName('thor-script').length === 0) { if (document.getElementsByClassName('thor-script').length === 0) {
// add jquery
loadScript( loadScript(
'thor-script', 'thor-script',
'https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js', 'https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js',
) )
// add ebithor-claiming.1.3.js
loadScript( loadScript(
'thor-script', 'thor-script',
`${thorApiUrl}/resources/js/dataclaiming/ebithor-claiming.1.3.js`, `${thorApiUrl}/resources/js/dataclaiming/ebithor-claiming.1.3.js`,
() => thorApplicationNamespace.loadClaimingInfo(), () => thorApplicationNamespace.loadClaimingInfo(),
) )
} }
// THOR JS scripts communicates with the client app (your frontend) with browser events.
// You must register an event listener like this, assuming your event handler function is called "handleThorEvent "
// The event 'handleThorEvent' occurs when a message is received through the event source
// kan gagne ene message dans window la, nu apel sa function 'handleThorEvent' la.
if (window.addEventListener) { if (window.addEventListener) {
window.addEventListener('message', this.handleThorEvent, false) window.addEventListener('message', this.handleThorEvent, false)
} else { } else {
window.attachEvent('onmessage', this.handleThorEvent) window.attachEvent('onmessage', this.handleThorEvent)
} }
} }
componentDidMount() { componentDidMount() {
if (typeof thorApplicationNamespace === 'undefined') return if (typeof thorApplicationNamespace === 'undefined') return
console.log('componentDidMount function initialised ...')
thorApplicationNamespace.loadClaimingInfo() thorApplicationNamespace.loadClaimingInfo()
console.log('Successfully loaded claimingInfo() inside componentDidMount ...')
} }
componentWillUnmount() { componentWillUnmount() {
console.log('componentWillUnmount function initialised ...')
if (window.addEventListener) { if (window.addEventListener) {
window.removeEventListener('message', this.handleThorEvent, false) window.removeEventListener('message', this.handleThorEvent, false)
} else { } else {
...@@ -126,61 +106,30 @@ class OrcidClaim extends React.Component { ...@@ -126,61 +106,30 @@ class OrcidClaim extends React.Component {
if (this.state.loadingTimeoutEvent !== null) if (this.state.loadingTimeoutEvent !== null)
window.clearTimeout(this.state.loadingTimeoutEvent) window.clearTimeout(this.state.loadingTimeoutEvent)
} }
// Here we implement the event handler handleThorEvent() that will cover the THOR events we're interested in
handleThorEvent = event => { handleThorEvent = event => {
try { try {
if (typeof thorApplicationNamespace === 'undefined') return if (typeof thorApplicationNamespace === 'undefined') return
console.log('handleThorEvent function -- event.data (the actual message sent to event listener): ', event.data)
switch (event.data) { switch (event.data) {
case thorApplicationNamespace.notify.fatalError: case thorApplicationNamespace.notify.fatalError:
console.log(
'Fatal Error! thorApplicationNamespace.notify.fatalError',
)
this.callErrorCallbackIfRequired(false, event) this.callErrorCallbackIfRequired(false, event)
break break
case thorApplicationNamespace.notify.errorOccurred: // Called after error is returned from Thor
case thorApplicationNamespace.notify.errorOccurred:
// Called after processing error returned from Thor WS.
// check thorApplicationNamespace.errorReturned to get JSON error's description
console.log(
'errorOccurred! processing error returned from Thor WS',
)
this.state.claimed || this.state.claimed ||
this.checkIfAlreadyClaimed(this.props.citation, this.state.userData) this.checkIfAlreadyClaimed(this.props.citation, this.state.userData)
? this.callSuccessCallback() ? this.callSuccessCallback()
: this.callErrorCallbackIfRequired(false, event) : this.callErrorCallbackIfRequired(false, event)
break break
case thorApplicationNamespace.notify.claimEnd: // Called after the claim is done into orcid record case thorApplicationNamespace.notify.claimEnd: // Called after the claim is done into orcid record
console.log(
'claimEnd! The claim is done into orcid record',
)
this.setState({ claimed: true }) this.setState({ claimed: true })
break break
case thorApplicationNamespace.notify.popupClosed: case thorApplicationNamespace.notify.popupClosed:
console.log(
'popupClosed! Called after the login/logout ORCID redirection\'s popup window is closed',
)
this.callErrorCallbackIfRequired(true) this.callErrorCallbackIfRequired(true)
break break
case thorApplicationNamespace.notify.loadingComplete: case thorApplicationNamespace.notify.loadingComplete:
// Called when the user clicks the link to login thru ORCID authentication.
console.log("thorApplicationNamespace.isSignedIn(): ", thorApplicationNamespace.isSignedIn())
console.log("thorApplicationNamespace.userData: ", JSON.stringify(thorApplicationNamespace.userData))
if ( if (
thorApplicationNamespace.isSignedIn() && thorApplicationNamespace.isSignedIn() &&
thorApplicationNamespace.userData !== null thorApplicationNamespace.userData !== null
) { ) {
console.log("loadingComplete -- thor.loading.complete: ", JSON.stringify(thorApplicationNamespace.userData))
this.setState({ this.setState({
userData: JSON.parse( userData: JSON.parse(
JSON.stringify(thorApplicationNamespace.userData), JSON.stringify(thorApplicationNamespace.userData),
...@@ -193,23 +142,16 @@ class OrcidClaim extends React.Component { ...@@ -193,23 +142,16 @@ class OrcidClaim extends React.Component {
) )
? this.callSuccessCallback() ? this.callSuccessCallback()
: this.claimToOrcid() : this.claimToOrcid()
} else { } else this.callErrorCallbackIfRequired(false)
this.callErrorCallbackIfRequired(false)
console.log("loadingComplete ERROR-- thor.loading.complete ERROR: ", JSON.stringify(thorApplicationNamespace.userData))
}
break break
default: default:
break break
} }
} catch (e) { } catch (e) {
this.callErrorCallbackIfRequired(false, e) this.callErrorCallbackIfRequired(false, e)
console.log("Error in handleThorEvent function. Could not get into switch statements")
throw e throw e
} }
} }
checkIfAlreadyClaimed = (newWork, userData) => { checkIfAlreadyClaimed = (newWork, userData) => {
if ('works' in userData && userData.works instanceof Array) { if ('works' in userData && userData.works instanceof Array) {
const allWorkIds = [] const allWorkIds = []
...@@ -231,12 +173,10 @@ class OrcidClaim extends React.Component { ...@@ -231,12 +173,10 @@ class OrcidClaim extends React.Component {
} }
return false return false
} }
claimToOrcid = () => { claimToOrcid = () => {
thorApplicationNamespace.orcIdWork = this.props.citation thorApplicationNamespace.orcIdWork = this.props.citation
thorApplicationNamespace.addWork() thorApplicationNamespace.addWork()
} }
loginToOrcid = () => { loginToOrcid = () => {
thorApplicationNamespace.notifyClientApp( thorApplicationNamespace.notifyClientApp(
thorApplicationNamespace.notify.loginClick, thorApplicationNamespace.notify.loginClick,
...@@ -244,7 +184,6 @@ class OrcidClaim extends React.Component { ...@@ -244,7 +184,6 @@ class OrcidClaim extends React.Component {
const url = thorApplicationNamespace.getLoginUrl() const url = thorApplicationNamespace.getLoginUrl()
window.open(url, 'ORCID') window.open(url, 'ORCID')
} }
logoutFromOrcid = () => { logoutFromOrcid = () => {
const url = thorApplicationNamespace.getLogoutUrl() const url = thorApplicationNamespace.getLogoutUrl()
thorApplicationNamespace.callWS(url, () => {}, '', 'GET') thorApplicationNamespace.callWS(url, () => {}, '', 'GET')
...@@ -254,14 +193,12 @@ class OrcidClaim extends React.Component { ...@@ -254,14 +193,12 @@ class OrcidClaim extends React.Component {
null, null,
) )
} }
callSuccessCallback = () => { callSuccessCallback = () => {
this.props.successCallback(this.state.userData) this.props.successCallback(this.state.userData)
this.setState({ claimed: true }) this.setState({ claimed: true })
this.callErrorCallbackIfRequired(false) this.callErrorCallbackIfRequired(false)
this.logoutFromOrcid() this.logoutFromOrcid()
} }
callErrorCallbackIfRequired = (isLoading, error = null) => { callErrorCallbackIfRequired = (isLoading, error = null) => {
const timeoutEvent = this.state.loadingTimeoutEvent const timeoutEvent = this.state.loadingTimeoutEvent
this.setState({ this.setState({
...@@ -281,7 +218,6 @@ class OrcidClaim extends React.Component { ...@@ -281,7 +218,6 @@ class OrcidClaim extends React.Component {
this.logoutFromOrcid() this.logoutFromOrcid()
} }
} }
render() { render() {
const ShowComponent = this.props.showComponent const ShowComponent = this.props.showComponent
return ( return (
......
...@@ -164,7 +164,6 @@ class SubmitComplete extends React.Component { ...@@ -164,7 +164,6 @@ class SubmitComplete extends React.Component {
) : ( ) : (
<React.Fragment> <React.Fragment>
<p> <p>
<div>{JSON.stringify(orcidObject)}</div>
<OrcidClaim <OrcidClaim
citation={orcidObject} citation={orcidObject}
errorCallback={event => { errorCallback={event => {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment