Skip to content

Commit ec3bd6e

Browse files
committed
feat: improve View/State/Service
1 parent 186a373 commit ec3bd6e

17 files changed

Lines changed: 104 additions & 139 deletions

src/WebUI/WWW/Controls/WebApp/AdvancedSearch.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ public AdvancedSearch(IPageContext pageContext, ISitemapManager sitemapManager)
3737
Stage.Controls =
3838
[
3939
new ControlAdvancedSearch("mySearch")
40-
{
41-
RestUri = _=> sitemapManager.GetUri<Api._1_.MonkeyIslandGameWql>(pageContext.ApplicationContext)
42-
},
40+
.DataService<Api._1_.MonkeyIslandGameWql>(),
4341
new ControlDataTile("myTile")
4442
{
4543
Bind = _=> new Binding().Add(new BindSearch() { Source = "mySearch" })
@@ -51,9 +49,7 @@ public AdvancedSearch(IPageContext pageContext, ISitemapManager sitemapManager)
5149

5250
Stage.Code = @"
5351
new ControlAdvancedSearch(""mySearch"")
54-
{
55-
RestUri = _=> sitemapManager.GetUri<Api._1_.MonkeyIslandBoatWql>(pageContext.ApplicationContext)
56-
},
52+
.DataService<Api._1_.MonkeyIslandGameWql>(),
5753
new ControlDataTile(""myTile"")
5854
{
5955
Bind = _=> new BindSearch() { Source = ""mySearch"" }

src/WebUI/WWW/Controls/WebApp/DataAvatarDropdown.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
using WebExpress.Tutorial.WebUI.WebFragment.ControlPage;
1+
using WebExpress.Tutorial.WebUI.WebFragment.ControlPage;
22
using WebExpress.Tutorial.WebUI.WebPage;
33
using WebExpress.Tutorial.WebUI.WebScope;
44
using WebExpress.Tutorial.WebUI.WWW.Api._1_;
55
using WebExpress.WebApp.WebApiControl;
6+
using WebExpress.WebApp.WebControl;
67
using WebExpress.WebApp.WebScope;
78
using WebExpress.WebCore.WebAttribute;
89
using WebExpress.WebCore.WebPage;
@@ -29,15 +30,11 @@ public DataAvatarDropdown(ISitemapManager sitemapManager, IPageContext pageConte
2930
Stage.Description = @"The `DataAvatarDropdown` control is the REST-enabled variant of the standard `AvatarDropdown`. It displays an avatar that opens an interactive dropdown menu, but the menu items are retrieved dynamically from a REST API endpoint.";
3031

3132
Stage.Control = new ControlDataAvatarDropdown()
32-
{
33-
RestUri = _ => sitemapManager.GetUri<AvatarDropdown>(pageContext.ApplicationContext)
34-
};
33+
.DataService<AvatarDropdown>();
3534

3635
Stage.Code = @"
3736
new ControlDataAvatarDropdown()
38-
{
39-
RestUri = _=> sitemapManager.GetUri<MonkeyIslandInventoriesDropdown>(pageContext.ApplicationContext)
40-
};";
37+
.DataService<AvatarDropdown>();";
4138
}
4239
}
4340
}

src/WebUI/WWW/Controls/WebApp/DataComment/DataComposer.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,24 @@ public sealed class DataComposer : PageControl
3535
/// <param name="sitemapManager">The sitemap manager.</param>
3636
public DataComposer(IPageContext pageContext, IComponentHub componentHub, ISitemapManager sitemapManager)
3737
{
38-
var uri = sitemapManager.GetUri<MonkeyIslandComment>(pageContext);
39-
4038
Stage.Description = @"`ControlCommentComposer` renders the **authoring surface** of the threaded comment widget. It emits a host element that the client-side `webexpress.webapp.CommentComposerCtrl` turns into a *minimalist single-line trigger* (looks like an empty input). On focus or click the trigger collapses out of the way and the full form takes over - category select, WYSIWYG editor (powered by `webexpress.webui.EditorCtrl`), labels input and send / cancel buttons.";
4139

4240
Stage.Controls =
4341
[
4442
new ControlDataCommentComposer("tutorial-comment-composer-guybrush")
4543
{
46-
RestUri = _ => uri,
4744
CurrentUser = _ => "guybrush",
4845
Margin = _ => new PropertySpacingMargin(PropertySpacing.Space.Two, PropertySpacing.Space.None, PropertySpacing.Space.None, PropertySpacing.Space.None)
4946
}
47+
.DataService<MonkeyIslandComment>()
5048
];
5149

5250
Stage.Code = @"
53-
new ControlCommentComposer(""tutorial-comment-composer-guybrush"")
51+
new ControlDataCommentComposer(""tutorial-comment-composer-guybrush"")
5452
{
55-
RestUri = _ => sitemapManager.GetUri<MonkeyIslandComment>(pageContext),
5653
CurrentUser = _ => ""guybrush""
57-
};";
54+
}
55+
.DataService<MonkeyIslandComment>();";
5856
}
5957
}
6058
}

src/WebUI/WWW/Controls/WebApp/DataDropdown.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
using WebExpress.Tutorial.WebUI.Model;
1+
using WebExpress.Tutorial.WebUI.Model;
22
using WebExpress.Tutorial.WebUI.WebControl;
33
using WebExpress.Tutorial.WebUI.WebFragment.ControlPage;
44
using WebExpress.Tutorial.WebUI.WebPage;
55
using WebExpress.Tutorial.WebUI.WebScope;
66
using WebExpress.Tutorial.WebUI.WWW.Api._1_;
77
using WebExpress.WebApp.WebApiControl;
8+
using WebExpress.WebApp.WebControl;
89
using WebExpress.WebApp.WebScope;
910
using WebExpress.WebCore.WebAttribute;
1011
using WebExpress.WebCore.WebPage;
@@ -42,9 +43,9 @@ public DataDropDown(IPageContext pageContext, ISitemapManager sitemapManager)
4243
[
4344
new ControlDataDropdown("inventoryDropdown")
4445
{
45-
Text = _ => "Inventory",
46-
RestUri = _=> sitemapManager.GetUri<MonkeyIslandInventoriesDropdown>(pageContext.ApplicationContext)
46+
Text = _ => "Inventory"
4747
}
48+
.DataService<MonkeyIslandInventoriesDropdown>()
4849
.Add(new ControlDropdownItemLink()
4950
{
5051
Text = _ => "Add Item",
@@ -61,18 +62,18 @@ public DataDropDown(IPageContext pageContext, ISitemapManager sitemapManager)
6162
[
6263
new ControlDataDropdown("darkInventoryDropdown")
6364
{
64-
Text = _ => "Inventory",
65-
RestUri = _=> sitemapManager.GetUri<MonkeyIslandInventoriesDropdown>(pageContext.ApplicationContext)
65+
Text = _ => "Inventory"
6666
}
67+
.DataService<MonkeyIslandInventoriesDropdown>()
6768
];
6869

6970
// code sample
7071
Stage.Code = @"
7172
new ControlDataDropdown(""inventoryDropdown"")
7273
{
73-
Text = _ => ""Inventory"",
74-
RestUri = _ => sitemapManager.GetUri<MonkeyIslandInventoriesDropdown>(pageContext.ApplicationContext)
74+
Text = _ => ""Inventory""
7575
}
76+
.DataService<MonkeyIslandInventoriesDropdown>()
7677
.Add(new ControlDropdownItemLink()
7778
{
7879
Text = _ => ""Add Item"",
@@ -86,14 +87,14 @@ public DataDropDown(IPageContext pageContext, ISitemapManager sitemapManager)
8687
// properties: Api
8788
Stage.AddProperty
8889
(
89-
"RestUri",
90-
"The REST endpoint from which the entries are loaded.",
91-
"RestUri = _ => sitemapManager.GetUri<MonkeyIslandInventory>(pageContext.ApplicationContext)",
90+
"DataService",
91+
"The data service whose endpoint delivers the entries.",
92+
".DataService<MonkeyIslandInventoriesDropdown>()",
9293
new ControlDataDropdown("p_api")
9394
{
94-
Text = _ => "Inventory",
95-
RestUri = _ => sitemapManager.GetUri<MonkeyIslandInventoriesDropdown>(pageContext.ApplicationContext)
95+
Text = _ => "Inventory"
9696
}
97+
.DataService<MonkeyIslandInventoriesDropdown>()
9798
);
9899

99100
// properties: MaxItems
@@ -105,9 +106,9 @@ public DataDropDown(IPageContext pageContext, ISitemapManager sitemapManager)
105106
new ControlDataDropdown("p_maxitems")
106107
{
107108
Text = _ => "Inventory",
108-
RestUri = _ => sitemapManager.GetUri<MonkeyIslandInventoriesDropdown>(pageContext.ApplicationContext),
109109
MaxItems = _ => 10
110110
}
111+
.DataService<MonkeyIslandInventoriesDropdown>()
111112
);
112113

113114
// properties: SearchPlaceholder
@@ -119,9 +120,9 @@ public DataDropDown(IPageContext pageContext, ISitemapManager sitemapManager)
119120
new ControlDataDropdown("p_placeholder")
120121
{
121122
Text = _ => "Inventory",
122-
RestUri = _ => sitemapManager.GetUri<MonkeyIslandInventoriesDropdown>(pageContext.ApplicationContext),
123123
SearchPlaceholder = _ => "Search entries..."
124124
}
125+
.DataService<MonkeyIslandInventoriesDropdown>()
125126
);
126127
}
127128
}

src/WebUI/WWW/Controls/WebApp/DataFormEditor.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using WebExpress.Tutorial.WebUI.WebScope;
55
using WebExpress.Tutorial.WebUI.WWW.Api._1_;
66
using WebExpress.WebApp.WebControl;
7+
using WebExpress.WebApp.WebData;
78
using WebExpress.WebApp.WebScope;
89
using WebExpress.WebCore.WebAttribute;
910
using WebExpress.WebCore.WebHtml;
@@ -36,18 +37,20 @@ public DataFormEditor(IPageContext pageContext, ISitemapManager sitemapManager)
3637

3738
Stage.Control = new ControlDataFormEditor(RandomId.Create())
3839
{
39-
RestUri = _ => sitemapManager.GetUri<FormEditor>(pageContext).Add(new UriQuery("id", "00000000-0000-0000-0000-000000000001")),
4040
Preview = _ => true,
4141
Indent = _ => 18
42-
};
42+
}
43+
.Service("data", svc => svc
44+
.Uri(_ => sitemapManager.GetUri<FormEditor>(pageContext).Add(new UriQuery("id", "00000000-0000-0000-0000-000000000001"))));
4345

4446
Stage.Code = @"
45-
new ControlFormEditor(""my-form-editor"")
47+
new ControlDataFormEditor(""my-form-editor"")
4648
{
47-
RestUri = _=> sitemapManager.GetUri<FormEditor>(pageContext).Add(new UriQuery(""id"", ""00000000-0000-0000-0000-000000000001"")),
4849
Preview = _=> true,
4950
Indent = _=> 18
50-
};";
51+
}
52+
.Service(""data"", svc => svc
53+
.Uri(_ => sitemapManager.GetUri<FormEditor>(pageContext).Add(new UriQuery(""id"", ""00000000-0000-0000-0000-000000000001""))));";
5154

5255
Stage.AddProperty
5356
(
@@ -56,10 +59,11 @@ public DataFormEditor(IPageContext pageContext, ISitemapManager sitemapManager)
5659
"Readonly = true",
5760
new ControlDataFormEditor(RandomId.Create())
5861
{
59-
RestUri = _ => sitemapManager.GetUri<FormEditor>(pageContext).Add(new UriQuery("id", "00000000-0000-0000-0000-000000000001")),
6062
Readonly = _ => true,
6163
Margin = _ => new PropertySpacingMargin(PropertySpacing.Space.None, PropertySpacing.Space.Two)
6264
}
65+
.Service("data", svc => svc
66+
.Uri(_ => sitemapManager.GetUri<FormEditor>(pageContext).Add(new UriQuery("id", "00000000-0000-0000-0000-000000000001"))))
6367
);
6468
}
6569
}

src/WebUI/WWW/Controls/WebApp/DataInputCheck.cs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using WebExpress.Tutorial.WebUI.WebScope;
44
using WebExpress.Tutorial.WebUI.WWW.Api._1_;
55
using WebExpress.WebApp.WebApiControl;
6+
using WebExpress.WebApp.WebControl;
67
using WebExpress.WebApp.WebScope;
78
using WebExpress.WebCore.WebAttribute;
89
using WebExpress.WebCore.WebPage;
@@ -28,39 +29,39 @@ public sealed class DataInputCheck : PageControl
2829
/// <param name="sitemapManager">The sitemap manager for building REST endpoint URIs.</param>
2930
public DataInputCheck(IPageContext pageContext, ISitemapManager sitemapManager)
3031
{
31-
Stage.Description = @"The `ControlDataFormItemInputCheck` control extends `ControlFormItemInputCheck` and communicates with a REST API instead of persisting its state through cookies. On render, the client issues a GET request against the configured `RestUri` to retrieve the current checked state. If an `InitialChecked` value is provided, it takes precedence and the GET is skipped. Subsequent state changes are forwarded to the same endpoint via POST.";
32+
Stage.Description = @"The `ControlDataFormItemInputCheck` control extends `ControlFormItemInputCheck` and communicates with a REST API instead of persisting its state through cookies. On render, the client issues a GET request against the configured data service to retrieve the current checked state. If an `InitialChecked` value is provided, it takes precedence and the GET is skipped. Subsequent state changes are forwarded to the same endpoint via POST.";
3233

3334
Stage.Controls =
3435
[
3536
new ControlForm()
3637
.Add(new ControlDataFormItemInputCheck("lightCheck")
3738
{
38-
RestUri = _=> sitemapManager.GetUri<MonkeyIslandInsultModeCheck>(pageContext.ApplicationContext),
3939
Description = _ => "Enable insult sword fighting"
40-
})
40+
}
41+
.DataService<MonkeyIslandInsultModeCheck>())
4142
.AddPrimaryButton(new ControlFormItemButtonSubmit())
4243
];
4344

4445
Stage.Code = @"
4546
new ControlForm()
4647
.Add(new ControlDataFormItemInputCheck(""lightCheck"")
4748
{
48-
RestUri = _=> sitemapManager.GetUri<MonkeyIslandInsultModeCheck>(pageContext.ApplicationContext),
4949
Description = _ => ""Enable insult sword fighting""
50-
})
50+
}
51+
.DataService<MonkeyIslandInsultModeCheck>())
5152
.AddPrimaryButton(new ControlFormItemButtonSubmit())";
5253

5354
Stage.AddProperty
5455
(
55-
"RestUri",
56-
"Defines the REST API endpoint that reads and persists the checked state.",
57-
"RestUri = _ => sitemapManager.GetUri<MonkeyIslandInsultModeCheck>(pageContext.ApplicationContext)",
56+
"DataService",
57+
"Declares the data service that reads and persists the checked state.",
58+
".DataService<MonkeyIslandInsultModeCheck>()",
5859
new ControlForm()
5960
.Add(new ControlDataFormItemInputCheck("p_rest_uri")
6061
{
61-
RestUri = _ => sitemapManager.GetUri<MonkeyIslandInsultModeCheck>(pageContext.ApplicationContext),
6262
Description = _ => "Enable insult sword fighting"
63-
})
63+
}
64+
.DataService<MonkeyIslandInsultModeCheck>())
6465
.AddPrimaryButton(new ControlFormItemButtonSubmit())
6566
);
6667

@@ -72,10 +73,10 @@ public DataInputCheck(IPageContext pageContext, ISitemapManager sitemapManager)
7273
new ControlForm()
7374
.Add(new ControlDataFormItemInputCheck("p_initial_true")
7475
{
75-
RestUri = _ => sitemapManager.GetUri<MonkeyIslandInsultModeCheck>(pageContext.ApplicationContext),
7676
InitialChecked = _ => true,
7777
Description = _ => "Pre-checked without GET"
78-
})
78+
}
79+
.DataService<MonkeyIslandInsultModeCheck>())
7980
.AddPrimaryButton(new ControlFormItemButtonSubmit())
8081
);
8182

@@ -87,9 +88,9 @@ public DataInputCheck(IPageContext pageContext, ISitemapManager sitemapManager)
8788
new ControlForm()
8889
.Add(new ControlDataFormItemInputCheck("p_description")
8990
{
90-
RestUri = _ => sitemapManager.GetUri<MonkeyIslandInsultModeCheck>(pageContext.ApplicationContext),
9191
Description = _ => "Enable insult sword fighting"
92-
})
92+
}
93+
.DataService<MonkeyIslandInsultModeCheck>())
9394
.AddPrimaryButton(new ControlFormItemButtonSubmit())
9495
);
9596

@@ -101,10 +102,10 @@ public DataInputCheck(IPageContext pageContext, ISitemapManager sitemapManager)
101102
new ControlForm()
102103
.Add(new ControlDataFormItemInputCheck("p_layout")
103104
{
104-
RestUri = _ => sitemapManager.GetUri<MonkeyIslandInsultModeCheck>(pageContext.ApplicationContext),
105105
Layout = _ => TypeLayoutCheck.Switch,
106106
Description = _ => "Enable insult sword fighting"
107-
})
107+
}
108+
.DataService<MonkeyIslandInsultModeCheck>())
108109
.AddPrimaryButton(new ControlFormItemButtonSubmit())
109110
);
110111

@@ -116,10 +117,10 @@ public DataInputCheck(IPageContext pageContext, ISitemapManager sitemapManager)
116117
new ControlForm()
117118
.Add(new ControlDataFormItemInputCheck("p_inline")
118119
{
119-
RestUri = _ => sitemapManager.GetUri<MonkeyIslandInsultModeCheck>(pageContext.ApplicationContext),
120120
Inline = _ => true,
121121
Description = _ => "Inline"
122-
})
122+
}
123+
.DataService<MonkeyIslandInsultModeCheck>())
123124
.AddPrimaryButton(new ControlFormItemButtonSubmit())
124125
);
125126
}

0 commit comments

Comments
 (0)