CURA-5536 The api call does not return the package_count for the showcase, so we can't trust in that value. The total number of material packages by author is now calculated.

This commit is contained in:
Diego Prado Gesto 2018-07-13 15:13:38 +02:00
parent a8727d7b39
commit af697c6999
3 changed files with 12 additions and 4 deletions

View file

@ -9,7 +9,7 @@ import UM 1.1 as UM
Item Item
{ {
property int packageCount: toolbox.viewCategory == "material" ? model.package_count : 1 property int packageCount: toolbox.viewCategory == "material" ? toolbox.getTotalNumberOfPackagesByAuthor(model.id) : 1
property int installedPackages: toolbox.viewCategory == "material" ? toolbox.getNumberOfInstalledPackagesByAuthor(model.id) : (toolbox.isInstalled(model.id) ? 1 : 0) property int installedPackages: toolbox.viewCategory == "material" ? toolbox.getNumberOfInstalledPackagesByAuthor(model.id) : (toolbox.isInstalled(model.id) ? 1 : 0)
height: childrenRect.height height: childrenRect.height
Layout.alignment: Qt.AlignTop | Qt.AlignLeft Layout.alignment: Qt.AlignTop | Qt.AlignLeft

View file

@ -9,7 +9,7 @@ import UM 1.1 as UM
Rectangle Rectangle
{ {
property int packageCount: toolbox.viewCategory == "material" ? model.package_count : 1 property int packageCount: toolbox.viewCategory == "material" ? toolbox.getTotalNumberOfPackagesByAuthor(model.id) : 1
property int installedPackages: toolbox.viewCategory == "material" ? toolbox.getNumberOfInstalledPackagesByAuthor(model.id) : (toolbox.isInstalled(model.id) ? 1 : 0) property int installedPackages: toolbox.viewCategory == "material" ? toolbox.getNumberOfInstalledPackagesByAuthor(model.id) : (toolbox.isInstalled(model.id) ? 1 : 0)
id: tileBase id: tileBase
width: UM.Theme.getSize("toolbox_thumbnail_large").width + (2 * UM.Theme.getSize("default_lining").width) width: UM.Theme.getSize("toolbox_thumbnail_large").width + (2 * UM.Theme.getSize("default_lining").width)

View file

@ -228,6 +228,7 @@ class Toolbox(QObject, Extension):
self._makeRequestByType("authors") self._makeRequestByType("authors")
self._makeRequestByType("plugins_showcase") self._makeRequestByType("plugins_showcase")
self._makeRequestByType("materials_showcase") self._makeRequestByType("materials_showcase")
self._makeRequestByType("materials_available")
# Gather installed packages: # Gather installed packages:
self._updateInstalledModels() self._updateInstalledModels()
@ -506,8 +507,15 @@ class Toolbox(QObject, Extension):
count = 0 count = 0
for package in self._metadata["materials_installed"]: for package in self._metadata["materials_installed"]:
if package["author"]["author_id"] == author_id: if package["author"]["author_id"] == author_id:
if self.isInstalled(package["package_id"]): count += 1
count += 1 return count
@pyqtSlot(str, result = int)
def getTotalNumberOfPackagesByAuthor(self, author_id: str) -> int:
count = 0
for package in self._metadata["materials_available"]:
if package["author"]["author_id"] == author_id:
count += 1
return count return count
@pyqtSlot(str, result = bool) @pyqtSlot(str, result = bool)