Skip to content

Commit

Permalink
split KratosUiNodeInput view into multiple views
Browse files Browse the repository at this point in the history
  • Loading branch information
josxha committed Oct 20, 2023
1 parent 5375acb commit a94dde6
Show file tree
Hide file tree
Showing 11 changed files with 225 additions and 102 deletions.
38 changes: 36 additions & 2 deletions KratosSelfService/ViewComponents/KratosUiNodeInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,42 @@ namespace KratosSelfService.ViewComponents;

public class KratosUiNodeInput : ViewComponent
{
public async Task<ViewViewComponentResult> InvokeAsync(KratosUiNode text)
public async Task<ViewViewComponentResult> InvokeAsync(KratosUiNode node)
{
return View("Default", text);
switch (node.Type)
{
case KratosUiNode.TypeEnum.Text:
return View("Text", node);
case KratosUiNode.TypeEnum.Input:
switch (node.Attributes.GetKratosUiNodeInputAttributes().Type)
{
case KratosUiNodeInputAttributes.TypeEnum.Text:
case KratosUiNodeInputAttributes.TypeEnum.Password:
case KratosUiNodeInputAttributes.TypeEnum.Number:
case KratosUiNodeInputAttributes.TypeEnum.Hidden:
case KratosUiNodeInputAttributes.TypeEnum.Email:
case KratosUiNodeInputAttributes.TypeEnum.Tel:
case KratosUiNodeInputAttributes.TypeEnum.DatetimeLocal:
case KratosUiNodeInputAttributes.TypeEnum.Date:
case KratosUiNodeInputAttributes.TypeEnum.Url:
return View("InputField", node);
case KratosUiNodeInputAttributes.TypeEnum.Checkbox:
return View("InputCheckbox", node);
case KratosUiNodeInputAttributes.TypeEnum.Submit:
return View("InputSubmit", node);
case KratosUiNodeInputAttributes.TypeEnum.Button:
return View("InputButton", node);
default:
return View("InputDefault", node);
}
case KratosUiNode.TypeEnum.Img:
return View("Img", node);
case KratosUiNode.TypeEnum.A:
return View("Anchor", node);
case KratosUiNode.TypeEnum.Script:
return View("Script", node);
default:
return View("Default", node);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@model KratosUiNode

@{
var attributes = Model.Attributes.GetKratosUiNodeAnchorAttributes();
}

<div class="field">
<div class="is-fullwidth has-text-centered">
<a href="@attributes.Href" id="@attributes.Id">@attributes.Title.Text</a>
</div>
@foreach (var message in Model.Messages)
{
<KratosUiTextMessage Message="@message"/>
}
</div>
Original file line number Diff line number Diff line change
@@ -1,106 +1,7 @@
@model KratosUiNode

<div class="field">
@switch (Model.Type)
{
case KratosUiNode.TypeEnum.Text:
var textAttr = Model.Attributes.GetKratosUiNodeTextAttributes();
<p id="@textAttr.Id">@textAttr.Text.Text</p>
break;
case KratosUiNode.TypeEnum.Input:
var inputAttr = Model.Attributes.GetKratosUiNodeInputAttributes();
var label = inputAttr.Label ?? Model.Meta.Label;
switch (inputAttr.Type)
{
case KratosUiNodeInputAttributes.TypeEnum.Text:
case KratosUiNodeInputAttributes.TypeEnum.Password:
case KratosUiNodeInputAttributes.TypeEnum.Number:
case KratosUiNodeInputAttributes.TypeEnum.Hidden:
case KratosUiNodeInputAttributes.TypeEnum.Email:
case KratosUiNodeInputAttributes.TypeEnum.Tel:
case KratosUiNodeInputAttributes.TypeEnum.DatetimeLocal:
case KratosUiNodeInputAttributes.TypeEnum.Date:
case KratosUiNodeInputAttributes.TypeEnum.Url:
<label class="label" id="@label?.Id">
@(inputAttr.Label?.Text ?? Model.Meta.Label?.Text)
<div class="control">
<input type="@inputAttr.Type.ToString().ToLower()" class="input"
required="@inputAttr.Required"
value="@inputAttr.Value" autocomplete="@inputAttr.Autocomplete"
disabled="@inputAttr.Disabled" name="@inputAttr.Name"
onclick="@inputAttr.Onclick" pattern="@inputAttr.Pattern"/>
</div>
</label>
if (inputAttr.Type == KratosUiNodeInputAttributes.TypeEnum.Password && Model.Group == KratosUiNode.GroupEnum.Password)
{
<!--<div class="field">
<div class="control">
<div class="is-flex is-justify-content-space-between is-mobile">
<div>
-<label for="rememberMeCheck" class="checkbox">
<input type="checkbox" id="rememberMeCheck">
Remember me
</label>
</div>
<p>
<a href="recovery">
@OryTranslator.Get("login.forgot-password")
</a>
</p>
</div>
</div>
</div>-->
}
break;
case KratosUiNodeInputAttributes.TypeEnum.Checkbox:
break;
case KratosUiNodeInputAttributes.TypeEnum.Submit:
<div class="control mt-5">
<button type="@inputAttr.Type.ToString().ToLower()" class="button is-success is-fullwidth"
required="@inputAttr.Required"
disabled="@inputAttr.Disabled"
value="@inputAttr.Value"
name="@inputAttr.Name"
onclick="@inputAttr.Onclick">
@label?.Text
</button>
</div>
break;
case KratosUiNodeInputAttributes.TypeEnum.Button:
<div class="control mt-5">
<button type="@inputAttr.Type.ToString()" class="button is-light is-fullwidth"
required="@inputAttr.Required"
value="@inputAttr.Value" autocomplete="@inputAttr.Autocomplete"
disabled="@inputAttr.Disabled" name="@inputAttr.Name"
onclick="@inputAttr.Onclick" pattern="@inputAttr.Pattern">
@label?.Text
</button>
</div>
break;
}
break;
case KratosUiNode.TypeEnum.Img:
var imgAttr = Model.Attributes.GetKratosUiNodeImageAttributes();
<img src="@imgAttr.Src" class="image" height="@imgAttr.Height" width="@imgAttr.Width"
id="@imgAttr.Id" alt="image"/>
break;
case KratosUiNode.TypeEnum.A:
var anchorAttr = Model.Attributes.GetKratosUiNodeAnchorAttributes();
<div class="is-fullwidth has-text-centered">
<a href="@anchorAttr.Href" id="@anchorAttr.Id">@anchorAttr.Title.Text</a>
</div>
break;
case KratosUiNode.TypeEnum.Script:
var scriptAttr = Model.Attributes.GetKratosUiNodeScriptAttributes();
<script src="@scriptAttr.Src" async="@scriptAttr.Async"
crossorigin="@scriptAttr.Crossorigin" referrerpolicy="@scriptAttr.Referrerpolicy"
nonce="@scriptAttr.Nonce" integrity="@scriptAttr.Integrity"
id="@scriptAttr.Id"></script>
break;
default:
<p>Unsupported UI Type: @Model.Type</p>
break;
}
<p>Unsupported UI Type: @Model.Type</p>
@foreach (var message in Model.Messages)
{
<KratosUiTextMessage Message="@message"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@model KratosUiNode

@{
var attributes = Model.Attributes.GetKratosUiNodeImageAttributes();
}

<div class="field">
<img src="@attributes.Src" class="image" height="@attributes.Height" width="@attributes.Width"
id="@attributes.Id" alt="image"/>
@foreach (var message in Model.Messages)
{
<KratosUiTextMessage Message="@message"/>
}
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@model KratosUiNode

@{
var attributes = Model.Attributes.GetKratosUiNodeInputAttributes();
var label = attributes.Label ?? Model.Meta.Label;
}

<div class="field">
<div class="control mt-5">
<button type="button" class="button is-light is-fullwidth"
required="@attributes.Required"
value="@attributes.Value" autocomplete="@attributes.Autocomplete"
disabled="@attributes.Disabled" name="@attributes.Name"
onclick="@attributes.Onclick" pattern="@attributes.Pattern">
@label?.Text
</button>
</div>
@foreach (var message in Model.Messages)
{
<KratosUiTextMessage Message="@message"/>
}
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@model KratosUiNode

@{
var attributes = Model.Attributes.GetKratosUiNodeInputAttributes();
var label = attributes.Label ?? Model.Meta.Label;
}

<div class="field">
<input type="checkbox" class="input"
required="@attributes.Required"
value="@attributes.Value" autocomplete="@attributes.Autocomplete.ToString()?.ToLower()"
disabled="@attributes.Disabled" name="@attributes.Name"
onclick="@attributes.Onclick" pattern="@attributes.Pattern"/>
@switch (attributes.Type)
{
case KratosUiNodeInputAttributes.TypeEnum.Checkbox:
break;
default:
<p>Unsupported Input Type: @attributes.Type</p>
break;
}
@foreach (var message in Model.Messages)
{
<KratosUiTextMessage Message="@message"/>
}
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@model KratosUiNode

@{
var attributes = Model.Attributes.GetKratosUiNodeInputAttributes();
var label = attributes.Label ?? Model.Meta.Label;
}

<div class="field">
<p>Unsupported Input Type: "@attributes.Type, Label: "@label"</p>
@foreach (var message in Model.Messages)
{
<KratosUiTextMessage Message="@message"/>
}
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
@model KratosUiNode

@{
var attributes = Model.Attributes.GetKratosUiNodeInputAttributes();
var label = attributes.Label ?? Model.Meta.Label;
}

<div class="field">
<label class="label" id="@label?.Id">
@(attributes.Label?.Text ?? Model.Meta.Label?.Text)
<div class="control">
<input type="@attributes.Type.ToString().ToLower()" class="input"
required="@attributes.Required"
value="@attributes.Value" autocomplete="@attributes.Autocomplete.ToString()?.ToLower()"
disabled="@attributes.Disabled" name="@attributes.Name"
onclick="@attributes.Onclick" pattern="@attributes.Pattern"/>
</div>
</label>
@if (attributes.Type == KratosUiNodeInputAttributes.TypeEnum.Password
&& Model.Group == KratosUiNode.GroupEnum.Password)
{
<!--<div class="field">
<div class="control">
<div class="is-flex is-justify-content-space-between is-mobile">
<div>
-<label for="rememberMeCheck" class="checkbox">
<input type="checkbox" id="rememberMeCheck">
Remember me
</label>
</div>
<p>
<a href="recovery">
@OryTranslator.Get("login.forgot-password")
</a>
</p>
</div>
</div>
</div>-->
}

@foreach (var message in Model.Messages)
{
<KratosUiTextMessage Message="@message"/>
}
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@model KratosUiNode

@{
var attributes = Model.Attributes.GetKratosUiNodeInputAttributes();
var label = attributes.Label ?? Model.Meta.Label;
}

<div class="field">
<div class="control mt-5">
<button type="submit" class="button is-success is-fullwidth"
required="@attributes.Required"
disabled="@attributes.Disabled"
value="@attributes.Value"
name="@attributes.Name"
onclick="@attributes.Onclick">
@label?.Text
</button>
</div>
@foreach (var message in Model.Messages)
{
<KratosUiTextMessage Message="@message"/>
}
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@model KratosUiNode

@{
var attributes = Model.Attributes.GetKratosUiNodeScriptAttributes();
}

<div class="field">
<script src="@attributes.Src" async="@attributes.Async"
crossorigin="@attributes.Crossorigin" referrerpolicy="@attributes.Referrerpolicy"
nonce="@attributes.Nonce" integrity="@attributes.Integrity"
id="@attributes.Id"></script>
@foreach (var message in Model.Messages)
{
<KratosUiTextMessage Message="@message"/>
}
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@model KratosUiNode

@{
var attributes = Model.Attributes.GetKratosUiNodeTextAttributes();
}

<div class="field">
<p id="@attributes.Id">@attributes.Text.Text</p>
@foreach (var message in Model.Messages)
{
<KratosUiTextMessage Message="@message"/>
}
</div>

0 comments on commit a94dde6

Please sign in to comment.