refactoring: history

This commit is contained in:
Vinicius Moreira
2019-08-15 19:07:16 -03:00
parent 7e47cec300
commit 708385a8f3
4 changed files with 17 additions and 17 deletions

View File

@@ -4,7 +4,7 @@ from typing import List, Dict
from bauh_api.abstract.controller import ApplicationManager from bauh_api.abstract.controller import ApplicationManager
from bauh_api.abstract.handler import ProcessHandler from bauh_api.abstract.handler import ProcessHandler
from bauh_api.abstract.model import Application, ApplicationUpdate from bauh_api.abstract.model import Application, ApplicationUpdate, ApplicationHistory
from bauh_api.util.disk import DiskCacheLoader from bauh_api.util.disk import DiskCacheLoader
from bauh_api.util.disk import DiskCacheLoaderFactory from bauh_api.util.disk import DiskCacheLoaderFactory
from bauh_api.util.system import SystemProcess from bauh_api.util.system import SystemProcess
@@ -158,7 +158,7 @@ class GenericApplicationManager(ApplicationManager):
if man: if man:
return man.get_info(app) return man.get_info(app)
def get_history(self, app: Application): def get_history(self, app: Application) -> ApplicationHistory:
man = self._get_manager_for(app) man = self._get_manager_for(app)
if man: if man:

View File

@@ -4,15 +4,16 @@ from functools import reduce
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
from PyQt5.QtGui import QColor from PyQt5.QtGui import QColor
from PyQt5.QtWidgets import QDialog, QVBoxLayout, QTableWidget, QTableWidgetItem, QHeaderView from PyQt5.QtWidgets import QDialog, QVBoxLayout, QTableWidget, QTableWidgetItem, QHeaderView
from bauh_api.abstract.model import ApplicationHistory
from bauh_api.util.cache import Cache from bauh_api.util.cache import Cache
class HistoryDialog(QDialog): class HistoryDialog(QDialog):
def __init__(self, app: dict, icon_cache: Cache, locale_keys: dict): def __init__(self, app_history: ApplicationHistory, icon_cache: Cache, locale_keys: dict):
super(HistoryDialog, self).__init__() super(HistoryDialog, self).__init__()
self.setWindowTitle('{} - {} '.format(locale_keys['popup.history.title'], app['model'].base_data.name)) self.setWindowTitle('{} - {} '.format(locale_keys['popup.history.title'], app_history.app.base_data.name))
layout = QVBoxLayout() layout = QVBoxLayout()
self.setLayout(layout) self.setLayout(layout)
@@ -23,20 +24,20 @@ class HistoryDialog(QDialog):
table_history.verticalHeader().setVisible(False) table_history.verticalHeader().setVisible(False)
table_history.setAlternatingRowColors(True) table_history.setAlternatingRowColors(True)
table_history.setColumnCount(len(app['history'][0])) table_history.setColumnCount(len(app_history.history[0]))
table_history.setRowCount(len(app['history'])) table_history.setRowCount(len(app_history.history))
table_history.setHorizontalHeaderLabels([locale_keys.get(app['model'].get_type() + '.info.' + key, key).capitalize() for key in sorted(app['history'][0].keys())]) table_history.setHorizontalHeaderLabels([locale_keys.get(app_history.app.get_type() + '.history.' + key, key).capitalize() for key in sorted(app_history.history[0].keys())])
for row, commit in enumerate(app['history']): for row, commit in enumerate(app_history.history):
current_app_commit = app['model'].commit == commit['commit'] current_status = app_history.app_status_idx == row
for col, key in enumerate(sorted(commit.keys())): for col, key in enumerate(sorted(commit.keys())):
item = QTableWidgetItem() item = QTableWidgetItem()
item.setText(commit[key]) item.setText(commit[key])
item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)
if current_app_commit: if current_status:
item.setBackground(QColor('#ffbf00' if row != 0 else '#32CD32')) item.setBackground(QColor('#ffbf00' if row != 0 else '#32CD32'))
tip = '{}. {}.'.format(locale_keys['popup.history.selected.tooltip'], locale_keys['version.{}'.format('updated'if row == 0 else 'outdated')].capitalize()) tip = '{}. {}.'.format(locale_keys['popup.history.selected.tooltip'], locale_keys['version.{}'.format('updated'if row == 0 else 'outdated')].capitalize())
@@ -53,7 +54,7 @@ class HistoryDialog(QDialog):
new_width = reduce(operator.add, [table_history.columnWidth(i) for i in range(table_history.columnCount())]) new_width = reduce(operator.add, [table_history.columnWidth(i) for i in range(table_history.columnCount())])
self.resize(new_width, table_history.height()) self.resize(new_width, table_history.height())
icon_data = icon_cache.get(app['model'].base_data.icon_url) icon_data = icon_cache.get(app_history.app.base_data.icon_url)
if icon_data and icon_data.get('icon'): if icon_data and icon_data.get('icon'):
self.setWindowIcon(icon_data.get('icon')) self.setWindowIcon(icon_data.get('icon'))

View File

@@ -196,8 +196,7 @@ class GetAppHistory(QThread):
def run(self): def run(self):
if self.app: if self.app:
try: try:
res = {'model': self.app.model, 'history': self.manager.get_history(self.app.model)} self.signal_finished.emit({'history': self.manager.get_history(self.app.model)})
self.signal_finished.emit(res)
except (requests.exceptions.ConnectionError, NoInternetException): except (requests.exceptions.ConnectionError, NoInternetException):
self.signal_finished.emit({'error': self.locale_keys['internet.required']}) self.signal_finished.emit({'error': self.locale_keys['internet.required']})
finally: finally:

View File

@@ -658,16 +658,16 @@ class ManageWindow(QWidget):
dialog_info = InfoDialog(app=app_info, icon_cache=self.icon_cache, locale_keys=self.locale_keys, screen_size=self.screen_size) dialog_info = InfoDialog(app=app_info, icon_cache=self.icon_cache, locale_keys=self.locale_keys, screen_size=self.screen_size)
dialog_info.exec_() dialog_info.exec_()
def _finish_get_history(self, app: dict): def _finish_get_history(self, res: dict):
self.finish_action() self.finish_action()
self.change_update_state(change_filters=False) self.change_update_state(change_filters=False)
if app.get('error'): if res.get('error'):
self._handle_console_option(True) self._handle_console_option(True)
self.textarea_output.appendPlainText(app['error']) self.textarea_output.appendPlainText(res['error'])
self.checkbox_console.setChecked(True) self.checkbox_console.setChecked(True)
else: else:
dialog_history = HistoryDialog(app, self.icon_cache, self.locale_keys) dialog_history = HistoryDialog(res['history'], self.icon_cache, self.locale_keys)
dialog_history.exec_() dialog_history.exec_()
def _begin_search(self, word): def _begin_search(self, word):