Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
Commit 6cbb526e authored by g4m4's avatar g4m4
Browse files

[CODE] Better handling of a separate, customisable reporter name

parent 22730f76
No related branches found
No related tags found
No related merge requests found
......@@ -51,7 +51,7 @@ namespace {
fixit::PlayerData UFixItPlayerDataBaseConvertTo(const UFixItPlayerDataBase* PlayerData)
{
fixit::PlayerData Out = fixit::PlayerData(FFixItTranslationLayer::ToStd(PlayerData->PrefilledStr));
fixit::PlayerData Out = fixit::PlayerData(FFixItTranslationLayer::ToStd(PlayerData->GetStringData(true)));
for (const auto* Item : PlayerData->Items) {
if (Item != nullptr) {
Out.Items.emplace_back(UFixItPlayerDataItemConvertTo(Item));
......
......@@ -9,6 +9,7 @@
// FixIt module include, required for log category
#include "FixItCore.h"
#include "FixItSettings.h"
FString UFixItPlayerDataItem::GetType() const
{
......@@ -67,10 +68,6 @@ void UFixItPlayerDataBase::CollectAsync(TFunction<void(void)>&& completionCallba
{
OnDataCollected.BindLambda(completionCallback);
// ID
PrefilledStr.Append(FString::Format(TEXT("User {0}\n"),
{ FPlatformProcess::UserName(true) }));
CollectAsyncImpl();
}
......@@ -85,6 +82,24 @@ TArray<FString> UFixItPlayerDataBase::GetItemDescriptions() const
return result;
}
FString UFixItPlayerDataBase::GetStringData(bool IncludeUser) const
{
if (IncludeUser) {
const UFixItSettings* Settings = GetDefault<UFixItSettings>();
if (Settings) {
const FString Reporter = FString::Format(TEXT("User {0}\n"), { Settings->ReporterName });
return { Reporter
+ TEXT("\n")
+ PrefilledStr };
}
}
return PrefilledStr;
}
void UFixItPlayerDataBase::AppendToStringData(FString Data) {
PrefilledStr += Data;
}
void UFixItPlayerDataBase::CollectAsyncImpl()
{
// Nothing here
......
......@@ -8,6 +8,8 @@ THIRD_PARTY_INCLUDES_END
// ENGINE_MAJOR_VERSION
#include "Runtime/Launch/Resources/Version.h"
// FPlatformProcess::UserName
#include "HAL/PlatformProcess.h"
#include "FixItBackend.h"
#include "FixItCore.h"
......@@ -23,7 +25,8 @@ UFixItSettings::UFixItSettings()
bAllowCustomisingLabels(false),
bTitleIsMandatory(true),
bContentIsMandatory(true),
bAllowCredentialsOverride(true)
bAllowCredentialsOverride(true),
ReporterName(FPlatformProcess::UserName(true))
{
ReadSettingsFromConfig();
}
......@@ -43,6 +46,15 @@ bool UFixItSettings::SaveCredentials(const FString& NewLogin, const FString& New
}
Instance->Login = NewLogin;
Instance->Token = NewToken;
bool UFixItSettings::SaveReporterName(const FString& NewValue)
{
UFixItSettings* Instance = GetMutableDefault<UFixItSettings>();
if (Instance == nullptr)
{
UE_LOG(LogFixItCore, Error, TEXT("Could not save settings: mutable default settings could not be grabbed"));
return false;
}
Instance->ReporterName = NewValue;
#if WITH_EDITOR
Instance->PostEditChange();
......@@ -135,6 +147,10 @@ void UFixItSettings::ReadSettingsFromConfig() {
if (GConfig->GetValue(TEXT("/Script/FixItCore.FixItSettings"), TEXT("DefaultLabels"), DefaultLabels, InConfigFilename)) {
this->DefaultLabels = DefaultLabels;
}
int32 MaxTitleLength = 64;
if (GConfig->GetInt(TEXT("/Script/FixItCore.FixItSettings"), TEXT("MaxTitleLength"), MaxTitleLength, InConfigFilename)) {
this->MaxTitleLength = MaxTitleLength;
}
bool LoginAtStartup;
if (GConfig->GetBool(TEXT("/Script/FixItCore.FixItSettings"), TEXT("bLoginAtStartup"), LoginAtStartup, InConfigFilename)) {
this->bLoginAtStartup = LoginAtStartup;
......@@ -155,9 +171,11 @@ void UFixItSettings::ReadSettingsFromConfig() {
if (GConfig->GetBool(TEXT("/Script/FixItCore.FixItSettings"), TEXT("bAllowCredentialsOverride"), AllowCredentialsOverride, InConfigFilename)) {
this->bAllowCredentialsOverride = AllowCredentialsOverride;
}
int32 MaxTitleLength = 64;
if (GConfig->GetInt(TEXT("/Script/FixItCore.FixItSettings"), TEXT("MaxTitleLength"), MaxTitleLength, InConfigFilename)) {
this->MaxTitleLength = MaxTitleLength;
FString ReporterName;
if (GConfig->GetString(TEXT("/Script/FixItCore.FixItSettings"), TEXT("ReporterName"), ReporterName, InConfigFilename)) {
if (!ReporterName.IsEmpty()) {
this->ReporterName = ReporterName;
}
}
};
......
......@@ -11,7 +11,8 @@ FString FFixItTranslationLayer::FromStd(const std::string& Value) {
}
std::vector<std::string> FFixItTranslationLayer::ToStd(const TArray<FString>& Values) {
std::vector < std::string> out(Values.Num());
std::vector < std::string> out;
out.reserve(Values.Num());
for (const auto& value : Values) {
out.push_back(ToStd(value));
}
......
......@@ -74,8 +74,6 @@ public:
void CollectAsync(TFunction<void(void)>&& completionCallback);
// Text data that will be part of the description and is automatically filled based on context (bugit etc.)
// Set as BlueprintReadWrite so it can be edited
UPROPERTY(BlueprintReadWrite, Category = "FixIt")
FString PrefilledStr;
UPROPERTY(BlueprintReadWrite, Category = "FixIt")
......@@ -84,6 +82,12 @@ public:
UFUNCTION(BlueprintPure, Category = "FixIt")
TArray<FString> GetItemDescriptions() const;
UFUNCTION(BlueprintPure, Category = "FixIt")
FString GetStringData(bool IncludeUser) const;
UFUNCTION(BlueprintCallable, Category = "FixIt")
void AppendToStringData(FString Data);
protected:
virtual void CollectAsyncImpl();
......
......@@ -38,6 +38,15 @@ public:
UFUNCTION(BlueprintCallable, Category = "FixIt")
static bool SaveCredentials(const FString& NewLogin, const FString& NewToken);
/**
* Save the given reporter name to the settings config file
*
* @param NewValue The new reporter name
*
* @return True on success - false otherwise
*/
UFUNCTION(BlueprintCallable, Category = "FixIt")
static bool SaveReporterName(const FString& NewValue);
// Default identifiers
UPROPERTY(config, BlueprintReadOnly, Category = "Connection Settings", meta = (ToolTip = "Default login as a fallback to connect to the issue tracking platform"))
FString DefaultLogin;
......@@ -64,6 +73,11 @@ public:
UPROPERTY(config, EditAnywhere, BlueprintReadOnly, Category = "Bug Reporting", meta = (ToolTip = "Any labels that should be applied by defaults to any reported bug"))
TArray<FString> DefaultLabels;
UPROPERTY(config, EditAnywhere, BlueprintReadOnly, AdvancedDisplay, Category = "UI", meta = (ToolTip = "Max issue title length, make sure your backend supports it!"))
int32 MaxTitleLength = 64;
// All properties below are Unreal-specific and not part of FixItLib
UPROPERTY(config, EditAnywhere, BlueprintReadOnly, Category = "Connection Settings", meta = (ToolTip = "Whether login should be performed automatically at startup"))
uint32 bLoginAtStartup : 1;
......@@ -79,8 +93,8 @@ public:
UPROPERTY(config, EditAnywhere, BlueprintReadOnly, AdvancedDisplay, Category = "UI", meta = (ToolTip = "Allow the user to override the default credentials"))
uint32 bAllowCredentialsOverride : 1;
UPROPERTY(config, EditAnywhere, BlueprintReadOnly, AdvancedDisplay, Category = "UI", meta = (ToolTip = "Max issue title length, make sure your backend supports it!"))
int32 MaxTitleLength = 64;
UPROPERTY(config, EditAnywhere, BlueprintReadOnly, Category = "Bug Reporting", meta = (ToolTip = "Reporter name to be mentioned in the created issue"))
FString ReporterName;
// Begin UDeveloperSettings interface
virtual FName GetContainerName() const override { return FName("Project"); }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment