diff --git a/bin/init-data/stemmarest/init_test_data.sh b/bin/init-data/stemmarest/init_test_data.sh index 778d3115..44116ecd 100755 --- a/bin/init-data/stemmarest/init_test_data.sh +++ b/bin/init-data/stemmarest/init_test_data.sh @@ -57,6 +57,9 @@ else echo Created tradition $BESOIN_ID fi +echo; echo Adding stemweb_jobid 1 to Notre besoin +$CURL --request PUT --header 'Content-Type: application/json' --data '{"stemweb_jobid":1}' $STEMMAREST_ENDPOINT/tradition/$BESOIN_ID + echo ...and its stemma $CURL --request POST --header 'Content-Type: application/json' --data @data/besoin_stemma.json $STEMMAREST_ENDPOINT/tradition/$BESOIN_ID/stemma if [ $? -ne 0 ]; then @@ -80,6 +83,8 @@ if [ -z $FLOR_ID ]; then else echo Created tradition $FLOR_ID fi +echo; echo Adding stemweb_jobid 2 to Florilegium +$CURL --request PUT --header 'Content-Type: application/json' --data '{"stemweb_jobid":2}' $STEMMAREST_ENDPOINT/tradition/$FLOR_ID echo Uploading three sections for e in w x y; do $CURL --request POST --form name="section '$e'" --form file=@data/florilegium_${e}.csv --form filetype=csv $STEMMAREST_ENDPOINT/tradition/$FLOR_ID/section > /tmp/stemmarest.response @@ -149,6 +154,8 @@ if [ -z $ASNIP_ID ]; then else echo Created tradition $ASNIP_ID fi +echo; echo Adding stemweb_jobid 3 to Arabic test snippet +$CURL --request PUT --header 'Content-Type: application/json' --data '{"stemweb_jobid":3}' $STEMMAREST_ENDPOINT/tradition/$ASNIP_ID # No stemma echo; echo Creating admin-owned tradition diff --git a/frontend/www/src/js/modules/common/components/icons.js b/frontend/www/src/js/modules/common/components/icons.js index ae7759ff..4201c1e4 100644 --- a/frontend/www/src/js/modules/common/components/icons.js +++ b/frontend/www/src/js/modules/common/components/icons.js @@ -30,6 +30,40 @@ const svg_slide_indicator_active = ` `; +const job_running_indicator = ` + +`; + +const job_error_indicator = ` + +`; + const google_icon = ` `; diff --git a/frontend/www/src/js/modules/common/service/stemwebService.js b/frontend/www/src/js/modules/common/service/stemwebService.js index 51e7753b..3d1832da 100644 --- a/frontend/www/src/js/modules/common/service/stemwebService.js +++ b/frontend/www/src/js/modules/common/service/stemwebService.js @@ -142,25 +142,6 @@ class StemwebService extends BaseService { }); } - /** - * Lists the results of all jobs that have been run on the server by this - * user. - * - * @returns {Promise>} - */ - listRunResults() { - return this.fetch(`/result`).then((response) => { - if (response.success) { - /** @type {{ results: RunJobResult[] }} } */ - const data = response.data; - return data.results; - } - - // in case of failure, just return the response with the error - return response; - }); - } - /** * Gets the result of a job identified by the supplied `jobid` that has been * run on the server by this user. @@ -168,18 +149,15 @@ class StemwebService extends BaseService { * This can be used to periodically poll the server for the result of a job. * * @param jobid {string} The job ID of the job to fetch the result for. - * @returns {Promise>} + * @returns {Promise>} */ - getRunResult(jobid) { - return this.fetch(`/result`, undefined, { jobid }).then((response) => { - if (response.success) { - /** @type {{ results: RunJobResult[] }} } */ - const data = response.data; - return data.results.length > 0 ? data.results[0] : null; - } - - // in case of failure, just return the response with the error - return response; - }); + getRunResult( job_id ) { + if( job_id ) { + return this.fetch( `/algorithms/jobstatus/${job_id}` ).then((response) => { + return response; + }); + } else { + return Promise.resolve( { success: true, message:'OK', data: { jobid: job_id, result: "No job id given.", status: undefined } } ); + } } } diff --git a/frontend/www/src/js/modules/dashboard/tradition/editProperties.js b/frontend/www/src/js/modules/dashboard/tradition/editProperties.js index 95743c70..6ae4fc15 100644 --- a/frontend/www/src/js/modules/dashboard/tradition/editProperties.js +++ b/frontend/www/src/js/modules/dashboard/tradition/editProperties.js @@ -113,7 +113,6 @@ class EditProperties extends HTMLElement { static #handleUpdateTraditionMetadataResponse(resp) { if (resp.success) { StemmawebAlert.show('Metadata properties updated.', 'success'); - // @todo: Should the next line be wrapped in a try..catch? TRADITION_STORE.updateTradition(resp.data); return Promise.resolve({ success: true, diff --git a/frontend/www/src/js/modules/dashboard/tradition/stemwebFrontend.js b/frontend/www/src/js/modules/dashboard/tradition/stemwebFrontend.js index 593e2248..bc9c3773 100644 --- a/frontend/www/src/js/modules/dashboard/tradition/stemwebFrontend.js +++ b/frontend/www/src/js/modules/dashboard/tradition/stemwebFrontend.js @@ -189,6 +189,7 @@ class StemwebFrontend { handleRunAlgorithmResponse( resp ) { if (resp.success) { StemmawebAlert.show('Job added.', 'success'); + console.log( 'handleRunAlgorithmResponse =>', resp.data ); // // @todo: Should the next line be wrapped in a try..catch? // TRADITION_STORE.updateTradition(resp.data); return Promise.resolve({ diff --git a/frontend/www/src/js/modules/dashboard/tradition/stemwebJobStatus.js b/frontend/www/src/js/modules/dashboard/tradition/stemwebJobStatus.js index 4470ce3c..c708128b 100644 --- a/frontend/www/src/js/modules/dashboard/tradition/stemwebJobStatus.js +++ b/frontend/www/src/js/modules/dashboard/tradition/stemwebJobStatus.js @@ -1,33 +1,105 @@ class StemwebJobStatus extends HTMLElement { + constructor() { super(); - } - + // Whenever a new tradition / related stemma is selected, update the table + STEMMA_STORE.subscribe(({ parentTradition, selectedStemma }) => { + this.renderJobStatus( parentTradition.stemweb_jobid ); + }); + } + connectedCallback() { - this.render(); + // this.render(); + } + + renderJobStatus( job_id ) { + stemwebService.getRunResult( job_id ) + .then( this.handleJobStatusResponse ) + .then( (resp_data) => { this.render( resp_data ) } ); + } + + handleJobStatusResponse( resp ) { + if ( resp.success ) { + return new Promise( ( resolve, reject ) => { + resolve( resp.data ); + }); + } else { + StemmawebAlert.show(`Error: ${resp.message}`, 'danger'); + return new Promise( ( resolve, reject ) => { + resolve( undefined ); + }); + } + } + + + + statusTexts = { + 0: `Done`, + 1: `${job_running_indicator} Running` + } + + mapStatus( status ) { + return this.statusTexts[ status ] || `${job_error_indicator} Error` + } + + jobStatusLabels = { + job_id: 'Job', + status: 'Status', + result: 'Result' + }; + + metadataFromJobStatus( resp_data ) { + const labels = this.jobStatusLabels; + return [ + { + label: labels.job_id, + value: resp_data.jobid + }, + { + label: labels.status, + value: this.mapStatus( resp_data.status ) + }, + { label: labels.result, + value: resp_data.result + } + ] + } + + + renderJobStatusItem(item) { + return ` + + ${item.label} + ${item.value} + + `; } - render() { - const jobStatus = 'Hello World!' - this.innerHTML = ` -
- -
- - - ${jobStatus} - -
-
- -
- `; + render( resp_data ) { + if ( resp_data.jobid ) { + const statusItems = this.metadataFromJobStatus( resp_data ); + this.innerHTML = ` +
+ +
+ + + ${statusItems.map( this.renderJobStatusItem).join('\n') } + +
+
+ +
+ `; + } else { + this.innerHTML= ''; + } } } diff --git a/stemweb_mock/app.py b/stemweb_mock/app.py index acd11238..f7baf83a 100644 --- a/stemweb_mock/app.py +++ b/stemweb_mock/app.py @@ -1,4 +1,5 @@ from flask import Flask, request +import time app = Flask(__name__) @@ -151,7 +152,7 @@ def run_job(algo): # Allow query of a job ID. -@app.get('/algorithms/jobstatus/') +@app.get('/algorithms/jobstatus//') def query_job(jobid): if jobid == '1': return {"jobid":1,"status":0,"result":{