Skip to content

Commit

Permalink
Merge pull request #302 from ontoportal-lirmm/feature/migrate-fair-sc…
Browse files Browse the repository at this point in the history
…ore-js-code

Feature: Migrate fair score JS code to Stimulus controllers
  • Loading branch information
syphax-bouazzouni authored Jul 28, 2023
2 parents 041e43f + 53ac9bf commit 280748f
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 80 deletions.
1 change: 0 additions & 1 deletion app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
//= require bp_property_tree
//= require concepts
//= require home
//= require fair_score
//= require_tree ./helpers
//= require_tree ./components
//= require ontologies
Expand Down
21 changes: 21 additions & 0 deletions app/javascript/controllers/fair_score_home_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Controller } from "@hotwired/stimulus"
import {FairScorePrincipleBar, FairScoreCriteriaRadar, FairScoreChartContainer} from "../mixins/useFairScore";
// Connects to data-controller="fair-score-home"
export default class extends Controller {
connect() {
let fairScoreBar = new FairScorePrincipleBar( 'ont-fair-scores-canvas')
let fairScoreRadar = new FairScoreCriteriaRadar( 'ont-fair-criteria-scores-canvas')
let fairContainer = new FairScoreChartContainer('fair-score-charts-container' , [ fairScoreRadar , fairScoreBar])
let ontologies = jQuery("#ontology_ontologyId");

fairContainer.getFairScoreData("all")
ontologies.change( (e) => {
if(ontologies.val() !== null){
fairContainer.getFairScoreData(ontologies.val().join(','))
} else if(ontologies.val() === null){
fairContainer.getFairScoreData("all")
}
e.preventDefault()
})
}
}
20 changes: 20 additions & 0 deletions app/javascript/controllers/fair_score_landscape_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Controller } from "@hotwired/stimulus"
import { FairScoreChartContainer, FairScoreCriteriaBar } from "../mixins/useFairScore";
// Connects to data-controller="fair-score-landscape"
export default class extends Controller {
connect() {
let fairCriteriaBars = new FairScoreCriteriaBar('ont-fair-scores-criteria-bars-canvas')
let fairContainer = new FairScoreChartContainer('fair-score-charts-container' , [fairCriteriaBars])
let ontologies = jQuery("#ontology_ontologyId");

fairContainer.getFairScoreData("all")
ontologies.change( (e) => {
if(ontologies.val() !== null){
fairContainer.getFairScoreData(ontologies.val().join(','))
} else if(ontologies.val() === null){
fairContainer.getFairScoreData("all")
}
e.preventDefault()
})
}
}
12 changes: 12 additions & 0 deletions app/javascript/controllers/fair_score_summary_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Controller } from "@hotwired/stimulus"
import {FairScorePrincipleBar, FairScoreCriteriaRadar, FairScoreChartContainer} from "../mixins/useFairScore";
// Connects to data-controller="fair-score-summary"
export default class extends Controller {
connect() {
let fairScoreBar = new FairScorePrincipleBar( 'ont-fair-scores-canvas')
let fairScoreRadar = new FairScoreCriteriaRadar( 'ont-fair-criteria-scores-canvas')
let fairContainer = new FairScoreChartContainer('fair-score-charts-container' , [ fairScoreRadar , fairScoreBar])

fairContainer.getFairScoreData(window.location.pathname.split('/')[2])
}
}
12 changes: 9 additions & 3 deletions app/javascript/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ application.register("class-search-auto-complete", ClassSearchAutoCompleteContro
import ContainerSplitterController from "./container_splitter_controller"
application.register("container-splitter", ContainerSplitterController)

import FairScoreHomeController from "./fair_score_home_controller"
application.register("fair-score-home", FairScoreHomeController)

import FairScoreLandscapeController from "./fair_score_landscape_controller"
application.register("fair-score-landscape", FairScoreLandscapeController)

import FairScoreSummaryController from "./fair_score_summary_controller"
application.register("fair-score-summary", FairScoreSummaryController)

import FormAutoCompleteController from "./form_auto_complete_controller"
application.register("form-auto-complete", FormAutoCompleteController)

Expand Down Expand Up @@ -55,9 +64,6 @@ application.register("skos-collection-colors", SkosCollectionColorsController)
import TextTruncateController from "./text_truncate_controller"
application.register("text-truncate", TextTruncateController)

import Ontology_viewer_tabs_controller from "./ontology_viewer_tabs_controller"
application.register("ontology-viewer-tabs", Ontology_viewer_tabs_controller)

import TooltipController from "./tooltip_controller"
application.register("tooltip", TooltipController)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

function round(val , base = 1){
return Math.floor( val * 100 * base) / 100
}

function getObtainedNotObtainedNA(scoresIn, portalMax , max , normalize = true){
const delimiter = (val) => (normalize ? val : 1)
const notObtained = portalMax.map((x,i) => {
Expand Down Expand Up @@ -391,17 +391,17 @@ class FairScoreCriteriaRadar extends FairScoreChart{

getFairScoreDataSet() {
const scores = this.fairScoreChartCanvas.data('normalizedScores')
return [
{
label: 'Fair score',
data: scores,
fill: true,
backgroundColor: 'rgba(151, 187, 205, 0.2)',
borderColor: 'rgba(151, 187, 205, 1)',
pointBorderColor: 'rgba(151, 187, 205, 1)',
pointBackgroundColor: 'rgba(151, 187, 205, 1)'
}
]
return [
{
label: 'Fair score',
data: scores,
fill: true,
backgroundColor: 'rgba(151, 187, 205, 0.2)',
borderColor: 'rgba(151, 187, 205, 1)',
pointBorderColor: 'rgba(151, 187, 205, 1)',
pointBackgroundColor: 'rgba(151, 187, 205, 1)'
}
]
}


Expand Down Expand Up @@ -492,7 +492,7 @@ class FairScoreCriteriaBar extends FairScoreChart{

if (topOffset <= 0)
topOffset = 0
else if( (topOffset + tooltipEl.clientHeight) >= position.height)
else if( (topOffset + tooltipEl.clientHeight) >= position.height)
topOffset = position.height - tooltipEl.clientHeight

// Display, position, and set styles for font
Expand Down Expand Up @@ -627,63 +627,5 @@ class FairScoreCriteriaBar extends FairScoreChart{
}
}


/*
For landscape
*/
jQuery('#fairness_assessment').ready(()=> {
let fairCriteriaBars = new FairScoreCriteriaBar('ont-fair-scores-criteria-bars-canvas')
let fairContainer = new FairScoreChartContainer('fair-score-charts-container' , [fairCriteriaBars])
let ontologies = jQuery("#ontology_ontologyId");

fairContainer.getFairScoreData("all")
ontologies.change( (e) => {
if(ontologies.val() !== null){
fairContainer.getFairScoreData(ontologies.val().join(','))
} else if(ontologies.val() === null){
fairContainer.getFairScoreData("all")
}
e.preventDefault()
})
return false
})



/*
For the home
*/
jQuery('#fair-home').ready( function (e) {

let fairScoreBar = new FairScorePrincipleBar( 'ont-fair-scores-canvas')
let fairScoreRadar = new FairScoreCriteriaRadar( 'ont-fair-criteria-scores-canvas')
let fairContainer = new FairScoreChartContainer('fair-score-charts-container' , [ fairScoreRadar , fairScoreBar])
let ontologies = jQuery("#ontology_ontologyId");

fairContainer.getFairScoreData("all")
ontologies.change( (e) => {
if(ontologies.val() !== null){
fairContainer.getFairScoreData(ontologies.val().join(','))
} else if(ontologies.val() === null){
fairContainer.getFairScoreData("all")
}
e.preventDefault()
})
return false
})

/*
For the summary
*/
jQuery('#fair-summary').ready( function (e) {

let fairScoreBar = new FairScorePrincipleBar( 'ont-fair-scores-canvas')
let fairScoreRadar = new FairScoreCriteriaRadar( 'ont-fair-criteria-scores-canvas')
let fairContainer = new FairScoreChartContainer('fair-score-charts-container' , [ fairScoreRadar , fairScoreBar])

fairContainer.getFairScoreData(window.location.pathname.split('/')[2])

return false
})

export {round, getObtainedNotObtainedNA, FairScoreChartContainer, FairScoreChart, FairScorePrincipleBar, FairScoreCriteriaRadar, FairScoreCriteriaBar}

2 changes: 1 addition & 1 deletion app/views/home/_fair_score_home.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%div.col
%div.col{data:{controller:"fair-score-home"}}
%div.card.mb-3
%div.card-header.d-flex.justify-content-between
%span
Expand Down
2 changes: 1 addition & 1 deletion app/views/home/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
%hr.home-section-line/
.home-card.home-fair-scores
- if fairness_service_enabled?
%div#fair-home
%div#fair-home{data:{controller:"fair-score-home"}}
= render partial: "shared/fair_score_bars", locals: {data: nil}
%a{:href => "#fairDetails"}
%div.home-fair-details
Expand Down
2 changes: 1 addition & 1 deletion app/views/landscape/_fair_score_landscape.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
This interface shows how an ontology or a group responded successfully to O’FAIRe FAIRness assessment questions
%div
See details for each ontologies on the specific ontology summary pages
%div.card-body
%div.card-body{data:{controller:"fair-score-landscape"}}
%div#fair-score-charts-container.row
%div.col
%span.text-secondary.mt-4
Expand Down
2 changes: 1 addition & 1 deletion app/views/ontologies/_fairs_score.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class: "btn btn-primary w-100",
data: { show_modal_title_value: "FAIRness assessment questions", show_modal_size_value: 'modal-xl' },
)
%div.statistics_container
%div.statistics_container{data:{controller:"fair-score-summary"}}
%div
= render partial: "shared/fair_score_radar" , locals: {data: @fair_scores_data}
%div
Expand Down

0 comments on commit 280748f

Please sign in to comment.