Put samples on the web site
This commit is contained in:
		
							parent
							
								
									2e8a605d13
								
							
						
					
					
						commit
						de9102f38a
					
				| 
						 | 
					@ -18,5 +18,6 @@
 | 
				
			||||||
  <ItemGroup>
 | 
					  <ItemGroup>
 | 
				
			||||||
    <ProjectReference Include="..\..\Ooui.AspNetCore\Ooui.AspNetCore.csproj" />
 | 
					    <ProjectReference Include="..\..\Ooui.AspNetCore\Ooui.AspNetCore.csproj" />
 | 
				
			||||||
    <ProjectReference Include="..\..\Ooui\Ooui.csproj" />
 | 
					    <ProjectReference Include="..\..\Ooui\Ooui.csproj" />
 | 
				
			||||||
 | 
					    <ProjectReference Include="..\..\Samples\Samples.csproj" />
 | 
				
			||||||
  </ItemGroup>
 | 
					  </ItemGroup>
 | 
				
			||||||
</Project>
 | 
					</Project>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -29,5 +29,29 @@ namespace AspNetCoreMvc.Controllers
 | 
				
			||||||
            div.AppendChild (btn);
 | 
					            div.AppendChild (btn);
 | 
				
			||||||
            return new ElementResult (div);
 | 
					            return new ElementResult (div);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        static readonly Lazy<List<Samples.ISample>> lazySamples =
 | 
				
			||||||
 | 
					            new Lazy<List<Samples.ISample>> ((() => {
 | 
				
			||||||
 | 
					                var sampleType = typeof (Samples.ISample);
 | 
				
			||||||
 | 
					                var asm = sampleType.Assembly;
 | 
				
			||||||
 | 
					                var sampleTypes = asm.GetTypes ().Where (x => x.Name.EndsWith ("Sample", StringComparison.Ordinal) && x != sampleType);
 | 
				
			||||||
 | 
					                var samples = from t in sampleTypes let s = Activator.CreateInstance (t) as Samples.ISample where s != null select s;
 | 
				
			||||||
 | 
					                return samples.ToList ();
 | 
				
			||||||
 | 
					            }), true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public static List<Samples.ISample> Samples => lazySamples.Value;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        [Route("/Samples/Run/{name}")]
 | 
				
			||||||
 | 
					        public IActionResult Run (string name)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if (string.IsNullOrWhiteSpace (name) || name.Length > 32)
 | 
				
			||||||
 | 
					                return BadRequest ();
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            var s = Samples.FirstOrDefault (x => x.Title == name);
 | 
				
			||||||
 | 
					            if (s == null)
 | 
				
			||||||
 | 
					                return NotFound ();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return new ElementResult (s.CreateElement ());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -16,8 +16,9 @@
 | 
				
			||||||
    <div class="col-md-3">
 | 
					    <div class="col-md-3">
 | 
				
			||||||
        <h3>Samples</h3>
 | 
					        <h3>Samples</h3>
 | 
				
			||||||
        <ul>
 | 
					        <ul>
 | 
				
			||||||
            <li><a asp-area="" asp-controller="Samples" asp-action="Clicker">HTML Clicker</a></li>
 | 
								@foreach (var s in SamplesController.Samples) {
 | 
				
			||||||
            <li><a asp-area="" asp-controller="Samples" asp-action="XamarinFormsClicker">Xamarin Forms Clicker</a></li>
 | 
					                <li><a asp-area="" asp-controller="Samples" asp-action="Run" asp-route-name="@s.Title">@s.Title</a></li>
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
        </ul>
 | 
					        </ul>
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
    <div class="col-md-3">
 | 
					    <div class="col-md-3">
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,3 +1,4 @@
 | 
				
			||||||
@using AspNetCoreMvc
 | 
					@using AspNetCoreMvc
 | 
				
			||||||
@using AspNetCoreMvc.Models
 | 
					@using AspNetCoreMvc.Models
 | 
				
			||||||
 | 
					@using AspNetCoreMvc.Controllers
 | 
				
			||||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
 | 
					@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,8 +3,10 @@ using Ooui;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Samples
 | 
					namespace Samples
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    public class ButtonSample
 | 
					    public class ButtonSample : ISample
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					        public string Title => "Button that count clicks";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Button MakeButton ()
 | 
					        Button MakeButton ()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var button = new Button ("Click me!");
 | 
					            var button = new Button ("Click me!");
 | 
				
			||||||
| 
						 | 
					@ -23,6 +25,11 @@ namespace Samples
 | 
				
			||||||
            UI.Publish ("/shared-button", b);
 | 
					            UI.Publish ("/shared-button", b);
 | 
				
			||||||
            UI.Publish ("/button", MakeButton);
 | 
					            UI.Publish ("/button", MakeButton);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public Element CreateElement ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return MakeButton ();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,9 +5,16 @@ using Ooui;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Samples
 | 
					namespace Samples
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    public class DrawSample
 | 
					    public class DrawSample : ISample
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					        public string Title => "Collaborative Drawing";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public void Publish ()
 | 
					        public void Publish ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            UI.Publish ("/draw", CreateElement ());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public Element CreateElement ()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var heading = new Heading ("Draw");
 | 
					            var heading = new Heading ("Draw");
 | 
				
			||||||
            var subtitle = new Paragraph ("Click to draw a collaborative masterpiece");
 | 
					            var subtitle = new Paragraph ("Click to draw a collaborative masterpiece");
 | 
				
			||||||
| 
						 | 
					@ -41,9 +48,7 @@ namespace Samples
 | 
				
			||||||
            app.AppendChild (subtitle);
 | 
					            app.AppendChild (subtitle);
 | 
				
			||||||
            app.AppendChild (canvas);
 | 
					            app.AppendChild (canvas);
 | 
				
			||||||
            app.AppendChild (clearbtn);
 | 
					            app.AppendChild (clearbtn);
 | 
				
			||||||
            UI.Publish ("/draw", app);
 | 
					            return app;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,24 +6,13 @@ using Ooui;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Samples
 | 
					namespace Samples
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	public class FilesSample
 | 
					    public class FilesSample : ISample
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
 | 
					        public string Title => "Upload files";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public void Publish ()
 | 
							public void Publish ()
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			var heading = new Heading ("Upload Files");
 | 
					            var app = CreateElement ();
 | 
				
			||||||
			var subtitle = new Paragraph ("Upload files to the app");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			var uploadForm = new Form ();
 | 
					 | 
				
			||||||
			uploadForm.Action = "/files/upload";
 | 
					 | 
				
			||||||
			uploadForm.Method = "POST";
 | 
					 | 
				
			||||||
			uploadForm.EncodingType = "multipart/form-data";
 | 
					 | 
				
			||||||
			uploadForm.AppendChild (new Input (InputType.File) { Name = "file" });
 | 
					 | 
				
			||||||
			uploadForm.AppendChild (new Input (InputType.Submit) { Value = "Upload" });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			var app = new Div ();
 | 
					 | 
				
			||||||
			app.AppendChild (heading);
 | 
					 | 
				
			||||||
			app.AppendChild (subtitle);
 | 
					 | 
				
			||||||
			app.AppendChild (uploadForm);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
			UI.Publish ("/files", app);
 | 
								UI.Publish ("/files", app);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -133,5 +122,25 @@ namespace Samples
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			return -1;
 | 
								return -1;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
					
 | 
				
			||||||
 | 
					        public Element CreateElement ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            var heading = new Heading ("Upload Files");
 | 
				
			||||||
 | 
					            var subtitle = new Paragraph ("Upload files to the app");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            var uploadForm = new Form ();
 | 
				
			||||||
 | 
					            uploadForm.Action = "/files/upload";
 | 
				
			||||||
 | 
					            uploadForm.Method = "POST";
 | 
				
			||||||
 | 
					            uploadForm.EncodingType = "multipart/form-data";
 | 
				
			||||||
 | 
					            uploadForm.AppendChild (new Input (InputType.File) { Name = "file" });
 | 
				
			||||||
 | 
					            uploadForm.AppendChild (new Input (InputType.Submit) { Value = "Upload" });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            var app = new Div ();
 | 
				
			||||||
 | 
					            app.AppendChild (heading);
 | 
				
			||||||
 | 
					            app.AppendChild (subtitle);
 | 
				
			||||||
 | 
					            app.AppendChild (uploadForm);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return app;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,11 @@
 | 
				
			||||||
 | 
					using System;
 | 
				
			||||||
 | 
					using Ooui;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Samples
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public interface ISample
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        string Title { get; }
 | 
				
			||||||
 | 
					        Element CreateElement ();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -5,8 +5,10 @@ using Ooui;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Samples
 | 
					namespace Samples
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    public class TodoSample
 | 
					    public class TodoSample : ISample
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					        public string Title => "Global TODO list";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        List items = new List () {
 | 
					        List items = new List () {
 | 
				
			||||||
            ClassName = "list-group",
 | 
					            ClassName = "list-group",
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
| 
						 | 
					@ -106,6 +108,11 @@ namespace Samples
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            UI.Publish ("/todo", MakeTodo);
 | 
					            UI.Publish ("/todo", MakeTodo);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public Element CreateElement ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return MakeTodo ();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,8 +4,10 @@ using Ooui.Forms;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Samples
 | 
					namespace Samples
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	public class XamarinFormsSample
 | 
					    public class XamarinFormsSample : ISample
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
 | 
					        public string Title => "Xamarin.Forms Button Counter";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Page MakePage ()
 | 
							Page MakePage ()
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			Forms.Init ();
 | 
								Forms.Init ();
 | 
				
			||||||
| 
						 | 
					@ -46,5 +48,10 @@ namespace Samples
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            Ooui.UI.Publish ("/xamarin-forms", () => MakePage ().CreateElement ());
 | 
					            Ooui.UI.Publish ("/xamarin-forms", () => MakePage ().CreateElement ());
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
	}
 | 
					
 | 
				
			||||||
 | 
					        public Ooui.Element CreateElement ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return MakePage ().CreateElement ();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue