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 */
/* eslint-disable */
import React from 'react'
import styled from 'styled-components'
......@@ -51,9 +50,6 @@ const DefaultShowComponent = ({ onClick, isLoading }) => (
</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 = (
className,
url,
......@@ -64,7 +60,7 @@ const loadScript = (
script.classList.add(className)
script.src = url
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)
}
......@@ -80,44 +76,28 @@ class OrcidClaim extends React.Component {
claimed: false,
userData: null,
}
// Load THOr script in your front-end under a <script> tag.
if (document.getElementsByClassName('thor-script').length === 0) {
// add jquery
loadScript(
'thor-script',
'https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js',
)
// add ebithor-claiming.1.3.js
loadScript(
'thor-script',
`${thorApiUrl}/resources/js/dataclaiming/ebithor-claiming.1.3.js`,
() => 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) {
window.addEventListener('message', this.handleThorEvent, false)
} else {
window.attachEvent('onmessage', this.handleThorEvent)
}
}
componentDidMount() {
if (typeof thorApplicationNamespace === 'undefined') return
console.log('componentDidMount function initialised ...')
thorApplicationNamespace.loadClaimingInfo()
console.log('Successfully loaded claimingInfo() inside componentDidMount ...')
}
componentWillUnmount() {
console.log('componentWillUnmount function initialised ...')
if (window.addEventListener) {
window.removeEventListener('message', this.handleThorEvent, false)
} else {
......@@ -126,61 +106,30 @@ class OrcidClaim extends React.Component {
if (this.state.loadingTimeoutEvent !== null)
window.clearTimeout(this.state.loadingTimeoutEvent)
}
// Here we implement the event handler handleThorEvent() that will cover the THOR events we're interested in
handleThorEvent = event => {
try {
if (typeof thorApplicationNamespace === 'undefined') return
console.log('handleThorEvent function -- event.data (the actual message sent to event listener): ', event.data)
switch (event.data) {
case thorApplicationNamespace.notify.fatalError:
console.log(
'Fatal Error! thorApplicationNamespace.notify.fatalError',
)
this.callErrorCallbackIfRequired(false, event)
break
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',
)
case thorApplicationNamespace.notify.errorOccurred: // Called after error is returned from Thor
this.state.claimed ||
this.checkIfAlreadyClaimed(this.props.citation, this.state.userData)
? this.callSuccessCallback()
: this.callErrorCallbackIfRequired(false, event)
break
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 })
break
case thorApplicationNamespace.notify.popupClosed:
console.log(
'popupClosed! Called after the login/logout ORCID redirection\'s popup window is closed',
)
this.callErrorCallbackIfRequired(true)
break
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 (
thorApplicationNamespace.isSignedIn() &&
thorApplicationNamespace.userData !== null
) {
console.log("loadingComplete -- thor.loading.complete: ", JSON.stringify(thorApplicationNamespace.userData))
this.setState({
userData: JSON.parse(
JSON.stringify(thorApplicationNamespace.userData),
......@@ -193,23 +142,16 @@ class OrcidClaim extends React.Component {
)
? this.callSuccessCallback()
: this.claimToOrcid()
} else {
this.callErrorCallbackIfRequired(false)
console.log("loadingComplete ERROR-- thor.loading.complete ERROR: ", JSON.stringify(thorApplicationNamespace.userData))
}
} else this.callErrorCallbackIfRequired(false)
break
default:
break
}
} catch (e) {
this.callErrorCallbackIfRequired(false, e)
console.log("Error in handleThorEvent function. Could not get into switch statements")
throw e
}
}
checkIfAlreadyClaimed = (newWork, userData) => {
if ('works' in userData && userData.works instanceof Array) {
const allWorkIds = []
......@@ -231,12 +173,10 @@ class OrcidClaim extends React.Component {
}
return false
}
claimToOrcid = () => {
thorApplicationNamespace.orcIdWork = this.props.citation
thorApplicationNamespace.addWork()
}
loginToOrcid = () => {
thorApplicationNamespace.notifyClientApp(
thorApplicationNamespace.notify.loginClick,
......@@ -244,7 +184,6 @@ class OrcidClaim extends React.Component {
const url = thorApplicationNamespace.getLoginUrl()
window.open(url, 'ORCID')
}
logoutFromOrcid = () => {
const url = thorApplicationNamespace.getLogoutUrl()
thorApplicationNamespace.callWS(url, () => {}, '', 'GET')
......@@ -254,14 +193,12 @@ class OrcidClaim extends React.Component {
null,
)
}
callSuccessCallback = () => {
this.props.successCallback(this.state.userData)
this.setState({ claimed: true })
this.callErrorCallbackIfRequired(false)
this.logoutFromOrcid()
}
callErrorCallbackIfRequired = (isLoading, error = null) => {
const timeoutEvent = this.state.loadingTimeoutEvent
this.setState({
......@@ -281,7 +218,6 @@ class OrcidClaim extends React.Component {
this.logoutFromOrcid()
}
}
render() {
const ShowComponent = this.props.showComponent
return (
......
......@@ -164,7 +164,6 @@ class SubmitComplete extends React.Component {
) : (
<React.Fragment>
<p>
<div>{JSON.stringify(orcidObject)}</div>
<OrcidClaim
citation={orcidObject}
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