feat(advancedSettings): add setting to set the number of archived logs

Fixes #3610

Adds a setting in Advanced Settings to modify the number of archived logs to keep. Between 1 and 100
This commit is contained in:
Jonathan Rainville 2023-05-08 16:00:32 -04:00
parent 8e1d7cac05
commit 150a3d242e
7 changed files with 137 additions and 10 deletions

View File

@ -67,6 +67,16 @@ proc toggleWakuV2Store*(self: Controller) =
proc isWakuV2StoreEnabled*(self: Controller): bool =
return self.nodeConfigurationService.isWakuV2StoreEnabled()
proc getLogMaxBackups*(self: Controller): int =
return self.nodeConfigurationService.getLogMaxBackups()
proc setMaxLogBackups*(self: Controller, value: int) =
if(not self.nodeConfigurationService.setMaxLogBackups(value)):
# in the future we may do a call from here to show a popup about this error
error "an error occurred, we couldn't set the Max Log Backups"
return
self.delegate.onLogMaxBackupsChanged()
proc getWakuV2LightClientEnabled*(self: Controller): bool =
return self.nodeConfigurationService.getV2LightMode()

View File

@ -101,3 +101,12 @@ method isWakuV2StoreEnabled*(self: AccessInterface): bool {.base.} =
method toggleWakuV2Store*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method getLogMaxBackups*(self: AccessInterface): int {.base.} =
raise newException(ValueError, "No implementation available")
method setMaxLogBackups*(self: AccessInterface, value: int) {.base.} =
raise newException(ValueError, "No implementation available")
method onLogMaxBackupsChanged*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -139,3 +139,12 @@ method toggleWakuV2Store*(self: Module) =
method isWakuV2StoreEnabled*(self: Module): bool =
self.controller.isWakuV2StoreEnabled()
method getLogMaxBackups*(self: Module): int =
self.controller.getLogMaxBackups()
method setMaxLogBackups*(self: Module, value: int) =
self.controller.setMaxLogBackups(value)
method onLogMaxBackupsChanged*(self: Module) =
self.view.logMaxBackupsChanged()

View File

@ -132,3 +132,13 @@ QtObject:
proc toggleWakuV2Store*(self: View) {.slot.} =
self.delegate.toggleWakuV2Store()
proc logMaxBackupsChanged*(self: View) {.signal.}
proc getLogMaxBackups*(self: View): int {.slot.} =
return self.delegate.getLogMaxBackups()
QtProperty[int] logMaxBackups:
read = getLogMaxBackups
notify = logMaxBackupsChanged
proc setMaxLogBackups*(self: View, value: int) {.slot.} =
self.delegate.setMaxLogBackups(value)

View File

@ -79,16 +79,6 @@ proc init*(self: Service) =
error "error: ", errDesription
return
proc fetchNodeConfig(self: Service) =
try:
let response = status_node_config.getNodeConfig()
self.configuration = response.result.toNodeConfigDto()
except Exception as e:
let errDesription = e.msg
error "error: ", errDesription
return
proc saveConfiguration(self: Service, configuration: NodeConfigDto): bool =
if(not self.settingsService.saveNodeConfiguration(configuration.toJsonNode())):
error "error saving node configuration "
@ -294,3 +284,11 @@ proc setWakuV2StoreEnabled*(self: Service, enabled: bool, storeCapacity: int = 0
newConfiguration.WakuV2Config.StoreCapacity = storeCapacity
newConfiguration.WakuV2Config.StoreSeconds = storeSeconds
return self.saveConfiguration(newConfiguration)
proc getLogMaxBackups*(self: Service): int =
return self.configuration.LogMaxBackups
proc setMaxLogBackups*(self: Service, value: int): bool =
var newConfiguration = self.configuration
newConfiguration.LogMaxBackups = value
return self.saveConfiguration(newConfiguration)

View File

@ -14,6 +14,7 @@ QtObject {
property bool isAutoMessageEnabled: advancedModule? advancedModule.isAutoMessageEnabled : false
property bool isDebugEnabled: advancedModule? advancedModule.isDebugEnabled : false
property bool isWakuV2StoreEnabled: advancedModule ? advancedModule.isWakuV2StoreEnabled : false
property int logMaxBackups: advancedModule ? advancedModule.logMaxBackups : 1
property var customNetworksModel: advancedModule? advancedModule.customNetworksModel : []
@ -93,6 +94,13 @@ QtObject {
root.advancedModule.toggleDebug()
}
function setMaxLogBackups(value) {
if(!root.advancedModule)
return
root.advancedModule.setMaxLogBackups(value)
}
function enableDeveloperFeatures() {
if(!root.advancedModule)
return

View File

@ -11,10 +11,12 @@ import shared.popups 1.0
import shared.status 1.0
import StatusQ.Core 0.1
import StatusQ.Popups 0.1
import StatusQ.Popups.Dialog 0.1
import StatusQ.Components 0.1
import StatusQ.Core.Theme 0.1
import StatusQ.Controls 0.1
import StatusQ.Controls.Validators 0.1
import "../stores"
import "../controls"
@ -417,6 +419,16 @@ SettingsContentBase {
root.advancedStore.toggleFakeLoadingScreen()
}
}
StatusSettingsLineButton {
anchors.leftMargin: 0
anchors.rightMargin: 0
text: qsTr("How many log files to keep archived")
currentValue: root.advancedStore.logMaxBackups
onClicked: {
Global.openPopup(changeNumberOfLogsArchived)
}
}
}
FleetsModal {
@ -528,6 +540,77 @@ SettingsContentBase {
}
}
Component {
id: changeNumberOfLogsArchived
StatusModal {
id: logChangerModal
onClosed: destroy()
anchors.centerIn: parent
width: 400
header.title: qsTr("How many log files do you want to keep archived?")
contentItem: Column {
width: parent.width
StatusBaseText {
width: parent.width
font.pixelSize: 15
color: Theme.palette.directColor1
padding: 15
wrapMode: Text.WordWrap
text: qsTr("Choose a number between 1 and 100")
}
StatusInput {
id: numberInput
anchors.left: parent.left
anchors.right: parent.right
anchors.leftMargin: Style.current.padding
anchors.rightMargin: Style.current.padding
label: qsTr("Number of archives files")
input.text: root.advancedStore.logMaxBackups
placeholderText: qsTr("Number between 1 and 100")
validators: [
StatusFloatValidator {
bottom: 1
top: 100
errorMessage: qsTr("Number needs to be between 1 and 100")
locale: LocaleUtils.userInputLocale
}
]
}
StatusBaseText {
width: parent.width
font.pixelSize: 15
color: Theme.palette.directColor1
padding: 15
wrapMode: Text.WordWrap
text: qsTr("This change will only come into action after a restart")
}
}
rightButtons: [
StatusButton {
text: qsTr("Cancel")
onClicked: logChangerModal.close()
normalColor: "transparent"
hoverColor: "transparent"
},
StatusButton {
id: banButton
text: qsTr("Change")
type: StatusBaseButton.Type.Normal
onClicked: {
root.advancedStore.setMaxLogBackups(numberInput.input.text)
logChangerModal.close()
}
}
]
}
}
ConfirmationDialog {
id: confirmationPopup
property string experimentalFeature: ""