Skip to content

Commit 80af9c2

Browse files
committed
feat: add rest dropdown control, general improvements and minor bugs
1 parent cfe7734 commit 80af9c2

6 files changed

Lines changed: 395 additions & 14 deletions

File tree

src/WebUI/Model/Inventory.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using WebExpress.WebApp.WebRestApi;
3+
using WebExpress.WebCore.WebUri;
4+
5+
namespace WebExpress.Tutorial.WebUI.Model
6+
{
7+
/// <summary>
8+
/// Represents a data entity for a dropdown.
9+
/// </summary>
10+
public class Inventory : IRestApiCrudDropdownItem
11+
{
12+
/// <summary>
13+
/// Returns or sets the identifier of the table data.
14+
/// </summary>
15+
public Guid Id { get; set; } = Guid.NewGuid();
16+
17+
/// <summary>
18+
/// Returns or sets the name associated with the object.
19+
/// </summary>
20+
public string Text { get; set; }
21+
22+
/// <summary>
23+
/// Returns or sets the description associated with the object.
24+
/// </summary>
25+
public string Description { get; set; }
26+
27+
/// <summary>
28+
/// Returns or sets the URI as a string.
29+
/// </summary>
30+
public IUri Uri { get; set; }
31+
32+
/// <summary>
33+
/// Returns a string representation of the object, including its name, description, and appearances.
34+
/// </summary>
35+
/// <returns>A string containing the object's name, description, and the context in which it appears, formatted as
36+
/// multiple lines.</returns>
37+
public override string ToString()
38+
{
39+
return $"Text: {Text}\nDescription: {Description}";
40+
}
41+
}
42+
}

src/WebUI/Model/ViewModel.cs

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ public static class ViewModel
1212
/// </summary>
1313
public static List<Character> MonkeyIslandCharacters { get; } = [.. GetMonkeyIslandCharacters()];
1414

15+
/// <summary>
16+
/// Returns the list of inventories available in Monkey Island.
17+
/// </summary>
18+
public static List<Inventory> MonkeyIslanInventories { get; } = [.. GetMonkeyIslandInventories()];
19+
1520
/// <summary>
1621
/// Retrieves a collection of characters from the Monkey Island universe.
1722
/// </summary>
@@ -397,5 +402,143 @@ private static IEnumerable<Character> GetMonkeyIslandCharacters()
397402
AppearsIn = "Monkey Island 2: LeChuck’s Revenge (1991)"
398403
};
399404
}
405+
406+
/// <summary>
407+
/// Retrieves a collection of inventory items.
408+
/// </summary>
409+
/// <returns>An collection containing the inventory items.</returns>
410+
public static IEnumerable<Inventory> GetMonkeyIslandInventories()
411+
{
412+
// preferences / key items
413+
yield return new Inventory
414+
{
415+
Text = "Sword",
416+
Description = "A cutlass used for insult swordfighting and training with the Sword Master."
417+
};
418+
yield return new Inventory
419+
{
420+
Text = "Shovel",
421+
Description = "A sturdy shovel used to dig up treasure at the X-marked spot."
422+
};
423+
yield return new Inventory
424+
{
425+
Text = "Treasure Map (PTA Minutes)",
426+
Description = "Looks like PTA minutes, but actually leads to buried treasure on Melee Island."
427+
};
428+
yield return new Inventory
429+
{
430+
Text = "Spyglass",
431+
Description = "A handy spyglass for distant viewing; favored by lookouts and nosy pirates."
432+
};
433+
434+
// primary / main quest items
435+
yield return new Inventory
436+
{
437+
Text = "Rubber Chicken with a Pulley in the Middle",
438+
Description = "A rubber chicken fitted with a pulley, perfect for crossing improvised zip-lines."
439+
};
440+
yield return new Inventory
441+
{
442+
Text = "Head of the Navigator",
443+
Description = "A disembodied head that points the way through the ghost ship's catacombs."
444+
};
445+
yield return new Inventory
446+
{
447+
Text = "Navigator's Necklace",
448+
Description = "A mystical necklace that allows mingling with the ghostly realm aboard LeChuck's ship."
449+
};
450+
yield return new Inventory
451+
{
452+
Text = "Idol of Many Hands",
453+
Description = "A precious idol stolen from the Governor's mansion during a daring heist."
454+
};
455+
yield return new Inventory
456+
{
457+
Text = "Cooking Pot",
458+
Description = "A robust pot that doubles as protective headgear in questionable circus stunts."
459+
};
460+
yield return new Inventory
461+
{
462+
Text = "Gunpowder",
463+
Description = "Explosive powder used for making things go boom at the most inappropriate times."
464+
};
465+
yield return new Inventory
466+
{
467+
Text = "Rope",
468+
Description = "A length of rope that conveniently serves as a fuse and climbing aid."
469+
};
470+
yield return new Inventory
471+
{
472+
Text = "Root Beer",
473+
Description = "A fizzy beverage with voodoo properties effective against ghost pirates."
474+
};
475+
yield return new Inventory
476+
{
477+
Text = "Monkey Head Key",
478+
Description = "A peculiar key used to unlock the giant monkey head on Monkey Island."
479+
};
480+
yield return new Inventory
481+
{
482+
Text = "Directions to Monkey Island",
483+
Description = "Vital directions concocted via a questionable recipe to reach Monkey Island."
484+
};
485+
486+
// secondary / optional or situational items
487+
yield return new Inventory
488+
{
489+
Text = "Fish",
490+
Description = "A slippery fish; surprisingly useful for bribes, trolls, and culinary experiments."
491+
};
492+
yield return new Inventory
493+
{
494+
Text = "Hunk of Meat",
495+
Description = "A chunk of meat from the SCUMM Bar kitchen; perfect for distracting vicious dogs."
496+
};
497+
yield return new Inventory
498+
{
499+
Text = "Yellow Petals",
500+
Description = "Alchemically potent petals used to spice meat with... unforeseen side effects."
501+
};
502+
yield return new Inventory
503+
{
504+
Text = "Red Herring",
505+
Description = "A cheeky nautical snack and a blatant adventure-game tradition."
506+
};
507+
yield return new Inventory
508+
{
509+
Text = "Mug",
510+
Description = "A sturdy mug that, when filled with grog, tends to corrode in concerning ways."
511+
};
512+
yield return new Inventory
513+
{
514+
Text = "Mug o' Grog",
515+
Description = "Highly corrosive grog that eats through locks and tableware alike."
516+
};
517+
yield return new Inventory
518+
{
519+
Text = "\"I beat the Sword Master\" T-Shirt",
520+
Description = "A brag-worthy souvenir commemorating a victory over the Sword Master of Melee Island."
521+
};
522+
yield return new Inventory
523+
{
524+
Text = "Pieces of Eight",
525+
Description = "Shiny pirate currency used for shopping, bribery, and impulsive purchases."
526+
};
527+
yield return new Inventory
528+
{
529+
Text = "Breath Mints",
530+
Description = "Minty-fresh confidence boosters; surprisingly useful in social piracy."
531+
};
532+
yield return new Inventory
533+
{
534+
Text = "Bananas",
535+
Description = "A bunch of bananas favored by certain simian companions."
536+
};
537+
yield return new Inventory
538+
{
539+
Text = "Note",
540+
Description = "A handwritten note of dubious importance; pirates love leaving messages."
541+
};
542+
}
400543
}
401544
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using WebExpress.Tutorial.WebUI.Model;
4+
using WebExpress.WebApp.WebRestApi;
5+
using WebExpress.WebCore.WebApplication;
6+
using WebExpress.WebCore.WebAttribute;
7+
using WebExpress.WebCore.WebMessage;
8+
using WebExpress.WebCore.WebRestApi;
9+
using WebExpress.WebCore.WebSitemap;
10+
11+
namespace WebExpress.Tutorial.WebUI.WWW.Api._1
12+
{
13+
/// <summary>
14+
/// Represents a REST API dropdown for managing and retrieving data about Monkey Island inventory items.
15+
/// </summary>
16+
[Title("Monkey Island inventory")]
17+
[Method(CrudMethod.GET)]
18+
public sealed class MonkeyIslandInventory : RestApiCrudDropdown<Inventory>
19+
{
20+
/// <summary>
21+
/// Initializes a new instance of the class.
22+
/// </summary>
23+
/// <param name="sitemapManager">
24+
/// The sitemap manager used to retrieve URIs for the application context.
25+
/// </param>
26+
/// <param name="applicationContext">
27+
/// The application context containing the current state of the application.
28+
/// </param>
29+
public MonkeyIslandInventory(ISitemapManager sitemapManager, IApplicationContext applicationContext)
30+
{
31+
Data = ViewModel.MonkeyIslanInventories;
32+
}
33+
34+
/// <summary>
35+
/// Retrieves a collection of objects based on the specified WQL statement and request.
36+
/// </summary>
37+
/// <param name="filter">
38+
/// The filter used to query the data. This parameter defines the filtering and selection criteria.
39+
/// </param>
40+
/// <param name="request">
41+
/// The request context containing additional information for the operation.
42+
/// </param>
43+
/// <returns>
44+
/// An enumerable containing the objects that match the query criteria.
45+
/// </returns>
46+
public override IEnumerable<Inventory> GetData(string filter, Request request)
47+
{
48+
if (filter == null || filter == "null")
49+
{
50+
return Data;
51+
}
52+
53+
return Data
54+
.Where
55+
(
56+
x => x.Text.Contains(filter, System.StringComparison.InvariantCultureIgnoreCase)
57+
);
58+
}
59+
}
60+
}

src/WebUI/WWW/Controls/Dropdown.cs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public sealed class Dropdown : PageControl
2323
private readonly IControlDropdownItem _item2 = new ControlDropdownItemLink() { Text = "First Entry", Icon = new IconWrench() };
2424
private readonly IControlDropdownItem _item3 = new ControlDropdownItemLink() { Text = "Second Entry" };
2525
private readonly IControlDropdownItem _item4 = new ControlDropdownItemDivider();
26-
private readonly IControlDropdownItem _item5 = new ControlDropdownItemLink() { Text = "Third Entry" };
26+
private readonly IControlDropdownItem _item5 = new ControlDropdownItemLink() { Text = "Third Entry", Modal = "myModal" };
2727

2828
/// <summary>
2929
/// Initializes a new instance of the class.
@@ -39,29 +39,47 @@ public Dropdown(IPageContext pageContext, ISitemapManager sitemapManager)
3939
The `Dropdown` provides a button with a dropdown menu, offering a clean and efficient design.";
4040

4141
Stage.Controls = [
42-
new ControlDropdown(null, _item1, _item2, _item3, _item4, _item5)
42+
new ControlDropdown()
4343
{
4444
Text = "Dropdown",
4545
TextColor = new PropertyColorText(TypeColorText.Default),
4646
Color = new PropertyColorButton(TypeColorButton.Primary),
4747
}
48+
.Add(_item1)
49+
.Add(_item2)
50+
.Add(_item3)
51+
.Add(_item4)
52+
.Add(_item5),
53+
new ControlModalRemoteForm("myModal")
54+
{
55+
Header = "My modal",
56+
Size = TypeModalSize.ExtraLarge,
57+
Uri = sitemapManager.GetUri<Form.Index>(pageContext.ApplicationContext),
58+
Selector = "#conformationform"
59+
}
4860
];
4961

62+
Stage.DarkControls = [
63+
new ControlDropdown(null, _item1, _item2, _item3, _item4, _item5)
64+
{
65+
Text = "Dropdown",
66+
TextColor = new PropertyColorText(TypeColorText.Default),
67+
Color = new PropertyColorButton(TypeColorButton.Primary),
68+
}
69+
];
70+
5071
Stage.Code = @"
51-
new ControlDropdown
52-
(
53-
null,
54-
new ControlDropdownItemHeader() { Text = ""Header"" },
55-
new ControlDropdownItemLink() { Text = ""First Entry"", Icon = new IconWrench() },
56-
new ControlDropdownItemLink() { Text = ""Second Entry"" },
57-
new ControlDropdownItemDivider(),
58-
new ControlDropdownItemLink() { Text = ""Third Entry"" }
59-
)
72+
new ControlDropdown()
6073
{
6174
Text = ""Dropdown"",
6275
TextColor = new PropertyColorText(TypeColorText.Default),
6376
BackgroundColor = new PropertyColorButton(TypeColorButton.Primary)
64-
};";
77+
}
78+
.Add(new ControlDropdownItemHeader() { Text = ""Header"" })
79+
.Add(new ControlDropdownItemLink() { Text = ""First Entry"", Icon = new IconWrench() })
80+
.Add(new ControlDropdownItemLink() { Text = ""Second Entry"" })
81+
.Add(new ControlDropdownItemDivider())
82+
.Add(new ControlDropdownItemLink() { Text = ""Third Entry"", Modal = ""myModal"" });";
6583

6684
Stage.AddProperty
6785
(

0 commit comments

Comments
 (0)