Skip to content

Commit cd21479

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

6 files changed

Lines changed: 363 additions & 7 deletions

File tree

src/WebUI/Model/Location.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 location entity for a selection control within "The Secret of Monkey Island".
9+
/// </summary>
10+
public class Location : IRestApiCrudSelectionItem
11+
{
12+
/// <summary>
13+
/// Returns or sets the unique identifier of the location.
14+
/// </summary>
15+
public Guid Id { get; set; } = Guid.NewGuid();
16+
17+
/// <summary>
18+
/// Returns or sets the display name of the location.
19+
/// </summary>
20+
public string Text { get; set; }
21+
22+
/// <summary>
23+
/// Returns or sets a short description of the location.
24+
/// </summary>
25+
public string Description { get; set; }
26+
27+
/// <summary>
28+
/// Returns or sets an optional deep link target to the location.
29+
/// </summary>
30+
public IUri Uri { get; set; }
31+
32+
/// <summary>
33+
/// Returns or sets the island the location belongs to (e.g., "Melee Island", "Monkey Island").
34+
/// </summary>
35+
public string Island { get; set; }
36+
37+
/// <summary>
38+
/// Returns a string representation including name, description, and island.
39+
/// </summary>
40+
/// <returns>A multi-line string describing the location.</returns>
41+
public override string ToString()
42+
{
43+
return $"Text: {Text}\nDescription: {Description}\nIsland: {Island}";
44+
}
45+
}
46+
}

src/WebUI/Model/ViewModel.cs

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ public static class ViewModel
1717
/// </summary>
1818
public static List<Inventory> MonkeyIslanInventories { get; } = [.. GetMonkeyIslandInventories()];
1919

20+
/// <summary>
21+
/// Returns the list of predefined locations in Monkey Island.
22+
/// </summary>
23+
public static List<Location> MonkeyIslanLocations { get; } = [.. GetMonkeyIslandLocations()];
24+
2025
/// <summary>
2126
/// Retrieves a collection of characters from the Monkey Island universe.
2227
/// </summary>
@@ -540,5 +545,143 @@ public static IEnumerable<Inventory> GetMonkeyIslandInventories()
540545
Description = "A handwritten note of dubious importance; pirates love leaving messages."
541546
};
542547
}
548+
549+
/// <summary>
550+
/// Retrieves a collection of locations.
551+
/// </summary>
552+
/// <returns>An collection containing the locations.</returns>
553+
public static IEnumerable<Location> GetMonkeyIslandLocations()
554+
{
555+
// locations from "The Secret of Monkey Island" (1990)
556+
// melee island
557+
yield return new Location
558+
{
559+
Text = "Lookout Point",
560+
Description = "Clifftop vantage point where the Lookout keeps watch over Mêlée Island."
561+
};
562+
yield return new Location
563+
{
564+
Text = "Mêlée Island Village",
565+
Description = "Central village street with shops and notable buildings."
566+
};
567+
yield return new Location
568+
{
569+
Text = "Scumm Bar",
570+
Description = "Notorious pirate tavern by the docks."
571+
};
572+
yield return new Location
573+
{
574+
Text = "Docks",
575+
Description = "Harbor area where ships moor and the Scumm Bar is located."
576+
};
577+
yield return new Location
578+
{
579+
Text = "Jail",
580+
Description = "Small prison that houses characters like Otis."
581+
};
582+
yield return new Location
583+
{
584+
Text = "General Store",
585+
Description = "Village shop run by the shopkeeper."
586+
};
587+
yield return new Location
588+
{
589+
Text = "Church",
590+
Description = "Chapel used for certain story events."
591+
};
592+
yield return new Location
593+
{
594+
Text = "Alley",
595+
Description = "Narrow back alley with hidden goings-on."
596+
};
597+
yield return new Location
598+
{
599+
Text = "Governor's Mansion",
600+
Description = "Residence of Governor Elaine Marley, guarded by piranha poodles."
601+
};
602+
yield return new Location
603+
{
604+
Text = "Circus of the Fettuccini Brothers",
605+
Description = "Traveling circus for daring stunts and a few bruises."
606+
};
607+
yield return new Location
608+
{
609+
Text = "Forest",
610+
Description = "Maze-like woods that hide several paths and clearings."
611+
};
612+
yield return new Location
613+
{
614+
Text = "Fork in the Forest",
615+
Description = "Signposted fork that helps (or hinders) orientation."
616+
};
617+
yield return new Location
618+
{
619+
Text = "Sword Master's House",
620+
Description = "Secluded home of the Sword Master, reachable through the forest."
621+
};
622+
yield return new Location
623+
{
624+
Text = "Stan's Previously Owned Vessels",
625+
Description = "Shipyard where Stan sells second-hand ships with flair."
626+
};
627+
628+
// monkey island (key locations)
629+
yield return new Location
630+
{
631+
Text = "Landing Beach",
632+
Description = "Sandy shore where the Sea Monkey reaches Monkey Island."
633+
};
634+
yield return new Location
635+
{
636+
Text = "Jungle",
637+
Description = "Dense jungle covering most of the island."
638+
};
639+
yield return new Location
640+
{
641+
Text = "Herman Toothrot's Camp",
642+
Description = "Makeshift camp of castaway Herman Toothrot."
643+
};
644+
yield return new Location
645+
{
646+
Text = "Banana Grove",
647+
Description = "Spot to acquire bananas for a helpful primate."
648+
};
649+
yield return new Location
650+
{
651+
Text = "Lagoon",
652+
Description = "Quiet inland waterbody used in puzzle-solving."
653+
};
654+
yield return new Location
655+
{
656+
Text = "Cannibal Village",
657+
Description = "Huts of the vegetarian cannibals with unique interior design."
658+
};
659+
yield return new Location
660+
{
661+
Text = "Giant Stone Monkey Head",
662+
Description = "Ancient statue hiding an entrance to catacombs."
663+
};
664+
yield return new Location
665+
{
666+
Text = "Volcano Rim",
667+
Description = "Fiery heart of the island visible near the catacombs."
668+
};
669+
yield return new Location
670+
{
671+
Text = "Sea Monkey Wreck",
672+
Description = "The Sea Monkey in less-than-seaworthy condition on the shore."
673+
};
674+
yield return new Location
675+
{
676+
Text = "Catacombs",
677+
Description = "Underground passages leading to LeChuck's ghost ship."
678+
};
679+
yield return new Location
680+
{
681+
Text = "LeChuck's Ghost Ship",
682+
Description = "The dread pirate's vessel anchored in hidden waters."
683+
};
684+
685+
}
543686
}
544687
}

src/WebUI/WWW/Api/1/MonkeyIslandInventory.cs renamed to src/WebUI/WWW/Api/1/MonkeyIslandInventories.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace WebExpress.Tutorial.WebUI.WWW.Api._1
1515
/// </summary>
1616
[Title("Monkey Island inventory")]
1717
[Method(CrudMethod.GET)]
18-
public sealed class MonkeyIslandInventory : RestApiCrudDropdown<Inventory>
18+
public sealed class MonkeyIslandInventories : RestApiCrudDropdown<Inventory>
1919
{
2020
/// <summary>
2121
/// Initializes a new instance of the class.
@@ -26,7 +26,7 @@ public sealed class MonkeyIslandInventory : RestApiCrudDropdown<Inventory>
2626
/// <param name="applicationContext">
2727
/// The application context containing the current state of the application.
2828
/// </param>
29-
public MonkeyIslandInventory(ISitemapManager sitemapManager, IApplicationContext applicationContext)
29+
public MonkeyIslandInventories(ISitemapManager sitemapManager, IApplicationContext applicationContext)
3030
{
3131
Data = ViewModel.MonkeyIslanInventories;
3232
}
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 selection for managing and retrieving data about Monkey Island locations.
15+
/// </summary>
16+
[Title("Monkey Island location")]
17+
[Method(CrudMethod.GET)]
18+
public sealed class MonkeyIslandLocations : RestApiCrudSelection<Location>
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 MonkeyIslandLocations(ISitemapManager sitemapManager, IApplicationContext applicationContext)
30+
{
31+
Data = ViewModel.MonkeyIslanLocations;
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<Location> 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/RestDropdown.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public RestDropDown(IPageContext pageContext, ISitemapManager sitemapManager)
4141
new ControlRestDropdown("inventoryDropdown")
4242
{
4343
Text = "Inventory",
44-
RestUri = sitemapManager.GetUri<MonkeyIslandInventory>(pageContext.ApplicationContext)
44+
RestUri = sitemapManager.GetUri<MonkeyIslandInventories>(pageContext.ApplicationContext)
4545
}
4646
.Add(new ControlDropdownItemLink()
4747
{
@@ -56,7 +56,7 @@ public RestDropDown(IPageContext pageContext, ISitemapManager sitemapManager)
5656
new ControlRestDropdown("darkInventoryDropdown")
5757
{
5858
Text = "Inventory",
59-
RestUri = sitemapManager.GetUri<MonkeyIslandInventory>(pageContext.ApplicationContext)
59+
RestUri = sitemapManager.GetUri<MonkeyIslandInventories>(pageContext.ApplicationContext)
6060
}
6161
];
6262

@@ -82,7 +82,7 @@ public RestDropDown(IPageContext pageContext, ISitemapManager sitemapManager)
8282
new ControlRestDropdown("p_api")
8383
{
8484
Text = "Inventory",
85-
RestUri = sitemapManager.GetUri<MonkeyIslandInventory>(pageContext.ApplicationContext)
85+
RestUri = sitemapManager.GetUri<MonkeyIslandInventories>(pageContext.ApplicationContext)
8686
}
8787
);
8888

@@ -95,7 +95,7 @@ public RestDropDown(IPageContext pageContext, ISitemapManager sitemapManager)
9595
new ControlRestDropdown("p_maxitems")
9696
{
9797
Text = "Inventory",
98-
RestUri = sitemapManager.GetUri<MonkeyIslandInventory>(pageContext.ApplicationContext),
98+
RestUri = sitemapManager.GetUri<MonkeyIslandInventories>(pageContext.ApplicationContext),
9999
MaxItems = 10
100100
}
101101
);
@@ -109,7 +109,7 @@ public RestDropDown(IPageContext pageContext, ISitemapManager sitemapManager)
109109
new ControlRestDropdown("p_placeholder")
110110
{
111111
Text = "Inventory",
112-
RestUri = sitemapManager.GetUri<MonkeyIslandInventory>(pageContext.ApplicationContext),
112+
RestUri = sitemapManager.GetUri<MonkeyIslandInventories>(pageContext.ApplicationContext),
113113
SearchPlaceholder = "Search entries..."
114114
}
115115
);

0 commit comments

Comments
 (0)