mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-25 15:44:04 -06:00
Ensure that the local model is updated correctly on local vote
CURA-6013
This commit is contained in:
parent
098adc45ff
commit
99f0e96131
2 changed files with 28 additions and 23 deletions
|
@ -12,11 +12,6 @@ Item
|
||||||
|
|
||||||
property int numRatings: 0
|
property int numRatings: 0
|
||||||
|
|
||||||
// If the widget was used to vote, but the vote isn't sent to remote yet, we do want to fake some things.
|
|
||||||
property int _numRatings: _localRating != 0 ? numRatings + 1 : numRatings
|
|
||||||
property int _localRating: 0
|
|
||||||
onVisibleChanged: _localRating = 0 // Reset the _localRating
|
|
||||||
|
|
||||||
property int userRating: 0
|
property int userRating: 0
|
||||||
|
|
||||||
signal rated(int rating)
|
signal rated(int rating)
|
||||||
|
@ -60,10 +55,7 @@ Item
|
||||||
{
|
{
|
||||||
return indexHovered >= index
|
return indexHovered >= index
|
||||||
}
|
}
|
||||||
if(ratingWidget._localRating > 0)
|
|
||||||
{
|
|
||||||
return _localRating >= index +1
|
|
||||||
}
|
|
||||||
if(ratingWidget.userRating > 0)
|
if(ratingWidget.userRating > 0)
|
||||||
{
|
{
|
||||||
return userRating >= index +1
|
return userRating >= index +1
|
||||||
|
@ -86,25 +78,19 @@ Item
|
||||||
{
|
{
|
||||||
return "#5a5a5a"
|
return "#5a5a5a"
|
||||||
}
|
}
|
||||||
if((ratingWidget.indexHovered >= 0 || ratingWidget.userRating > 0 || ratingWidget._localRating > 0) && isStarFilled)
|
if((ratingWidget.indexHovered >= 0 || ratingWidget.userRating > 0) && isStarFilled)
|
||||||
{
|
{
|
||||||
return UM.Theme.getColor("primary")
|
return UM.Theme.getColor("primary")
|
||||||
}
|
}
|
||||||
return "#5a5a5a"
|
return "#5a5a5a"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onClicked:
|
onClicked: rated(index + 1) // Notify anyone who cares about this.
|
||||||
{
|
|
||||||
// Ensure that the local rating is updated (even though it's not on the server just yet)
|
|
||||||
//_localRating = index + 1
|
|
||||||
rated(index + 1)
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Label
|
Label
|
||||||
{
|
{
|
||||||
text: "(" + _numRatings + ")"
|
text: "(" + numRatings + ")"
|
||||||
verticalAlignment: Text.AlignVCenter
|
verticalAlignment: Text.AlignVCenter
|
||||||
height: parent.height
|
height: parent.height
|
||||||
color: "#5a5a5a"
|
color: "#5a5a5a"
|
||||||
|
|
|
@ -181,15 +181,34 @@ Item
|
||||||
onRated:
|
onRated:
|
||||||
{
|
{
|
||||||
toolbox.ratePackage(details.id, rating)
|
toolbox.ratePackage(details.id, rating)
|
||||||
var index = toolbox.packagesModel.find("id", details.id)
|
// HACK: This is a far from optimal solution, but without major refactoring, this is the best we can
|
||||||
|
// do. Since a rework of this is scheduled, it shouldn't live that long...
|
||||||
|
var index = toolbox.pluginsAvailableModel.find("id", details.id)
|
||||||
if(index != -1)
|
if(index != -1)
|
||||||
{
|
{
|
||||||
// Found the package
|
if(details.user_rating == 0) // User never rated before.
|
||||||
toolbox.packagesModel.setProperty(index, "user_rating", rating)
|
{
|
||||||
toolbox.packagesModel.setProperty(index, "num_ratings", details.num_ratings + 1)
|
toolbox.pluginsAvailableModel.setProperty(index, "num_ratings", details.num_ratings + 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
toolbox.pluginsAvailableModel.setProperty(index, "user_rating", rating)
|
||||||
|
|
||||||
|
|
||||||
// Hack; This is because the current selection is an outdated copy, so we need to re-copy it.
|
// Hack; This is because the current selection is an outdated copy, so we need to re-copy it.
|
||||||
base.selection = toolbox.packagesModel.getItem(index)
|
base.selection = toolbox.pluginsAvailableModel.getItem(index)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
index = toolbox.pluginsShowcaseModel.find("id", details.id)
|
||||||
|
if(index != -1)
|
||||||
|
{
|
||||||
|
if(details.user_rating == 0) // User never rated before.
|
||||||
|
{
|
||||||
|
toolbox.pluginsShowcaseModel.setProperty(index, "user_rating", rating)
|
||||||
|
}
|
||||||
|
toolbox.pluginsShowcaseModel.setProperty(index, "num_ratings", details.num_ratings + 1)
|
||||||
|
|
||||||
|
// Hack; This is because the current selection is an outdated copy, so we need to re-copy it.
|
||||||
|
base.selection = toolbox.pluginsShowcaseModel.getItem(index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue