|
1 | 1 |
|
2 | 2 | class StemwebJobStatus extends HTMLElement {
|
| 3 | + |
3 | 4 | constructor() {
|
4 | 5 | super();
|
5 |
| - } |
6 |
| - |
| 6 | + // Whenever a new tradition / related stemma is selected, update the table |
| 7 | + STEMMA_STORE.subscribe(({ parentTradition, selectedStemma }) => { |
| 8 | + this.renderJobStatus( parentTradition.stemweb_jobid ); |
| 9 | + }); |
| 10 | + } |
| 11 | + |
7 | 12 | connectedCallback() {
|
8 |
| - this.render(); |
| 13 | + // this.render(); |
| 14 | + } |
| 15 | + |
| 16 | + renderJobStatus( job_id ) { |
| 17 | + stemwebService.getRunResult( job_id ) |
| 18 | + .then( this.handleJobStatusResponse ) |
| 19 | + .then( (resp_data) => { this.render( resp_data ) } ); |
| 20 | + } |
| 21 | + |
| 22 | + handleJobStatusResponse( resp ) { |
| 23 | + if ( resp.success ) { |
| 24 | + return new Promise( ( resolve, reject ) => { |
| 25 | + resolve( resp.data ); |
| 26 | + }); |
| 27 | + } else { |
| 28 | + StemmawebAlert.show(`Error: ${resp.message}`, 'danger'); |
| 29 | + return new Promise( ( resolve, reject ) => { |
| 30 | + resolve( undefined ); |
| 31 | + }); |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | + statusTexts = { |
| 38 | + 0: `Done`, |
| 39 | + 1: `${job_running_indicator} Running` |
| 40 | + } |
| 41 | + |
| 42 | + mapStatus( status ) { |
| 43 | + return this.statusTexts[ status ] || `${job_error_indicator} Error` |
| 44 | + } |
| 45 | + |
| 46 | + jobStatusLabels = { |
| 47 | + job_id: 'Job', |
| 48 | + status: 'Status', |
| 49 | + result: 'Result' |
| 50 | + }; |
| 51 | + |
| 52 | + metadataFromJobStatus( resp_data ) { |
| 53 | + const labels = this.jobStatusLabels; |
| 54 | + return [ |
| 55 | + { |
| 56 | + label: labels.job_id, |
| 57 | + value: resp_data.jobid |
| 58 | + }, |
| 59 | + { |
| 60 | + label: labels.status, |
| 61 | + value: this.mapStatus( resp_data.status ) |
| 62 | + }, |
| 63 | + { label: labels.result, |
| 64 | + value: resp_data.result |
| 65 | + } |
| 66 | + ] |
| 67 | + } |
| 68 | + |
| 69 | + |
| 70 | + renderJobStatusItem(item) { |
| 71 | + return ` |
| 72 | + <tr> |
| 73 | + <td class="tradition-property-label-cell">${item.label}</td> |
| 74 | + <td class="tradition-property-value-cell">${item.value}</td> |
| 75 | + </tr> |
| 76 | + `; |
9 | 77 | }
|
10 | 78 |
|
11 |
| - render() { |
12 |
| - const jobStatus = 'Hello World!' |
13 |
| - this.innerHTML = ` |
14 |
| - <div class="position-sticky pt-3"> |
15 |
| - <h6 |
16 |
| - class="sidebar-heading d-flex justify-content-between align-items-center px-3 mt-4 mb-1 text-muted" |
17 |
| - > |
18 |
| - <span>Job status</span> |
19 |
| - <!--maybe-goes-here-a-button/--> |
20 |
| - </h6> |
21 |
| - <div class="table-responsive px-3 py-3"> |
22 |
| - <table class="table table-striped table-sm"> |
23 |
| - <tbody id="job_status"> |
24 |
| - ${jobStatus} |
25 |
| - </tbody> |
26 |
| - </table> |
27 |
| - </div> |
28 |
| -
|
29 |
| - </div> |
30 |
| - `; |
| 79 | + render( resp_data ) { |
| 80 | + if ( resp_data.jobid ) { |
| 81 | + const statusItems = this.metadataFromJobStatus( resp_data ); |
| 82 | + this.innerHTML = ` |
| 83 | + <div class="position-sticky pt-3"> |
| 84 | + <h6 |
| 85 | + class="sidebar-heading d-flex justify-content-between align-items-center px-3 mt-4 mb-1 text-muted" |
| 86 | + > |
| 87 | + <span>Job status</span> |
| 88 | + <!--maybe-goes-here-a-button/--> |
| 89 | + </h6> |
| 90 | + <div class="table-responsive px-3 py-3"> |
| 91 | + <table class="table table-striped table-sm"> |
| 92 | + <tbody id="job_status"> |
| 93 | + ${statusItems.map( this.renderJobStatusItem).join('\n') } |
| 94 | + </tbody> |
| 95 | + </table> |
| 96 | + </div> |
| 97 | +
|
| 98 | + </div> |
| 99 | + `; |
| 100 | + } else { |
| 101 | + this.innerHTML= ''; |
| 102 | + } |
31 | 103 | }
|
32 | 104 | }
|
33 | 105 |
|
|
0 commit comments