-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7447ed6
commit ce86cff
Showing
14 changed files
with
733 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<h3>Detail</h3> | ||
|
||
@code { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
@using Nerosoft.Starfish.Common | ||
@implements IDialogContentComponent<EditDialogArgs> | ||
|
||
@inject ISettingApi SettingApi | ||
@inject IToastService ToastService | ||
|
||
<FluentDialogHeader ShowDismiss="true"> | ||
<FluentStack VerticalAlignment="VerticalAlignment.Center"> | ||
<FluentIcon Value="@(new Icons.Regular.Size24.Settings())"/> | ||
<FluentLabel Typo="Typography.PaneHeader"> | ||
@Dialog.Instance.Parameters.Title | ||
</FluentLabel> | ||
</FluentStack> | ||
</FluentDialogHeader> | ||
|
||
<FluentDialogBody> | ||
<FluentStack Orientation="Orientation.Vertical"> | ||
<FluentTextField Style="width: 100%" | ||
Label="@(Resources.IDS_SETTING_EDIT_LABEL_ENVIRONMENT)" | ||
@bind-Value="Content.Environment" ReadOnly="true"/> | ||
|
||
<div style="height: 100%; width: 100%;"> | ||
<StandaloneCodeEditor @ref="_editor" CssClass="monaco-editor-container" ConstructionOptions="EditorConstructionOptions" OnDidInit="EditorOnDidInit" /> | ||
</div> | ||
</FluentStack> | ||
</FluentDialogBody> | ||
|
||
<FluentDialogFooter> | ||
<FluentButton Appearance="Appearance.Accent" OnClick="@SaveAsync" Loading="Loading">@(Resources.IDS_COMMON_SAVE)</FluentButton> | ||
<FluentButton Appearance="Appearance.Neutral" OnClick="@CancelAsync">@(Resources.IDS_COMMON_CANCEL)</FluentButton> | ||
</FluentDialogFooter> | ||
|
||
@code { | ||
|
||
[Parameter] | ||
public EditDialogArgs Content { get; set; } | ||
|
||
[CascadingParameter] | ||
public FluentDialog Dialog { get; set; } = default!; | ||
|
||
private string Mode => Content?.Properties?.TryGetValue("mode") as string; | ||
|
||
private string Format => Content?.Properties?.TryGetValue("format") as string; | ||
|
||
private StandaloneCodeEditor _editor = null!; | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
if (Mode == "update") | ||
{ | ||
await LoadValueAsync(); | ||
} | ||
} | ||
|
||
private StandaloneEditorConstructionOptions EditorConstructionOptions(StandaloneCodeEditor editor) | ||
{ | ||
var options = new StandaloneEditorConstructionOptions | ||
{ | ||
AutomaticLayout = true, | ||
Theme = "vs-dark" | ||
}; | ||
|
||
options.Language = Format switch | ||
{ | ||
Constants.Setting.FormatJson => "json", | ||
Constants.Setting.FormatText => "text", | ||
_ => options.Language | ||
}; | ||
|
||
return options; | ||
} | ||
|
||
private async Task EditorOnDidInit() | ||
{ | ||
await Task.CompletedTask; | ||
} | ||
|
||
private bool Loading { get; set; } | ||
|
||
private async Task SaveAsync() | ||
{ | ||
try | ||
{ | ||
Loading = true; | ||
var value = await _editor.GetValue(); | ||
var request = new SettingEditDto() | ||
{ | ||
Type = "diff", | ||
Data = Cryptography.Base64.Encrypt(value) | ||
}; | ||
var task = Mode switch | ||
{ | ||
"create" => SettingApi.CreateAsync(Content.AppId, Content.Environment, Format, request) | ||
.ContinueWith(task => | ||
{ | ||
task.WaitAndUnwrapException(); | ||
task.Result.EnsureSuccess(); | ||
}), | ||
"update" => SettingApi.UpdateAsync(Content.AppId, Content.Environment, Format, request) | ||
.ContinueWith(task => | ||
{ | ||
task.WaitAndUnwrapException(); | ||
task.Result.EnsureSuccess(); | ||
}), | ||
_ => Task.CompletedTask | ||
}; | ||
await task; | ||
await Dialog.CloseAsync(Content); | ||
} | ||
catch (Exception exception) | ||
{ | ||
var message = exception.GetPromptMessage(); | ||
ToastService.ShowError(message); | ||
} | ||
finally | ||
{ | ||
Loading = false; | ||
} | ||
} | ||
|
||
private async Task CancelAsync() | ||
{ | ||
await Dialog.CancelAsync(); | ||
} | ||
|
||
private Task LoadValueAsync() | ||
{ | ||
return SettingApi.GetItemsAsync(Content.AppId, Content.Environment, Format) | ||
.ContinueWith(task => | ||
{ | ||
task.WaitAndUnwrapException(); | ||
var value = Cryptography.Base64.Decrypt(task.Result.EnsureSuccess()); | ||
_editor.SetValue(value); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace Nerosoft.Starfish.Webapp.Pages.Setting; | ||
|
||
public class EditDialogArgs | ||
{ | ||
public EditDialogArgs(long appId, string environment) | ||
{ | ||
AppId = appId; | ||
Environment = environment; | ||
} | ||
|
||
public long AppId { get; set; } | ||
|
||
public string Environment { get; set; } | ||
|
||
public Dictionary<string, object> Properties { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
@implements IDialogContentComponent<EditDialogArgs> | ||
|
||
@inject ISettingApi SettingApi | ||
@inject IToastService ToastService | ||
|
||
<FluentDialogHeader ShowDismiss="true"> | ||
<FluentStack VerticalAlignment="VerticalAlignment.Center"> | ||
<FluentIcon Value="@(new Icons.Regular.Size24.Settings())"/> | ||
<FluentLabel Typo="Typography.PaneHeader"> | ||
@Dialog.Instance.Parameters.Title | ||
</FluentLabel> | ||
</FluentStack> | ||
</FluentDialogHeader> | ||
|
||
<FluentDialogBody> | ||
<FluentStack Orientation="Orientation.Vertical"> | ||
<FluentTextField Style="width: 100%" | ||
Label="Key" | ||
Value="@Key" ReadOnly="true"/> | ||
|
||
<FluentTextArea Style="width: 100%" | ||
Label="Value" | ||
@bind-Value="Request.Value"/> | ||
</FluentStack> | ||
</FluentDialogBody> | ||
|
||
<FluentDialogFooter> | ||
<FluentButton Appearance="Appearance.Accent" OnClick="@SaveAsync" Loading="Loading">@(Resources.IDS_COMMON_SAVE)</FluentButton> | ||
<FluentButton Appearance="Appearance.Neutral" OnClick="@CancelAsync">@(Resources.IDS_COMMON_CANCEL)</FluentButton> | ||
</FluentDialogFooter> | ||
|
||
@code { | ||
|
||
[Parameter] | ||
public EditDialogArgs Content { get; set; } | ||
|
||
[CascadingParameter] | ||
public FluentDialog Dialog { get; set; } = default!; | ||
|
||
private bool Loading { get; set; } | ||
|
||
private string Key => Content?.Properties?.TryGetValue("key") as string; | ||
|
||
private SettingValueUpdateDto Request { get; } = new(); | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
Request.Value = Content?.Properties?.TryGetValue("value") as string; | ||
await Task.CompletedTask; | ||
} | ||
|
||
private async Task SaveAsync() | ||
{ | ||
try | ||
{ | ||
Loading = true; | ||
await SettingApi.UpdateItemValueAsync(Content.AppId, Content.Environment, Key, Request) | ||
.ContinueWith(task => | ||
{ | ||
task.WaitAndUnwrapException(); | ||
task.Result.EnsureSuccess(); | ||
}); | ||
await Dialog.CloseAsync(Content); | ||
} | ||
catch (Exception exception) | ||
{ | ||
var message = exception.GetPromptMessage(); | ||
ToastService.ShowError(message); | ||
} | ||
finally | ||
{ | ||
Loading = false; | ||
} | ||
} | ||
|
||
private async Task CancelAsync() | ||
{ | ||
await Dialog.CancelAsync(); | ||
} | ||
|
||
} |
Oops, something went wrong.