-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Running total of score on review form (#4169)
Live score label added to edit review form Fixes #3963 Co-authored-by: Ghulam Murtaza <[email protected]> Co-authored-by: Saurabh Kumar <[email protected]>
- Loading branch information
1 parent
60484d9
commit 9153972
Showing
8 changed files
with
135 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ export default [ | |
...globals.browser, | ||
...globals.commonjs, | ||
jQuery: true, | ||
Alpine: true, | ||
}, | ||
}, | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* Alpine.js data component for calculating review scores in the form. | ||
* @returns {Object} The review score component object. | ||
*/ | ||
document.addEventListener("alpine:init", () => { | ||
Alpine.data("reviewScore", () => { | ||
return { | ||
/** @type {number} The calculated review score. */ | ||
totalScore: 0, | ||
|
||
/** | ||
* Initializes the component. | ||
* Sets up event listeners for score calculation if applicable. | ||
*/ | ||
init() { | ||
this.selectors = | ||
this.$el.querySelectorAll("[data-score-field]"); | ||
if (this.showScore) { | ||
this.calculateScore(); | ||
this.selectors.forEach((selector) => { | ||
selector.addEventListener( | ||
"change", | ||
this.calculateScore.bind(this) | ||
); | ||
}); | ||
} | ||
}, | ||
|
||
/** | ||
* Calculates the total score based on valid selector values. | ||
*/ | ||
calculateScore() { | ||
const validValues = [...this.selectors] | ||
.map((selector) => parseInt(selector.value)) | ||
.filter((value) => !isNaN(value) && value !== 99); | ||
|
||
this.totalScore = validValues.reduce((sum, value) => sum + value, 0); | ||
}, | ||
|
||
/** | ||
* Determines if the score should be shown. | ||
* @returns {boolean} True if there are selectors, false otherwise. | ||
*/ | ||
get showScore() { | ||
return this.selectors.length > 0; | ||
}, | ||
}; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters