/// <summary> /// enumerates all things of scene's selected elements /// if a Digidoc is the only selected, then the Pages of the Digidoc are enumerated /// </summary> /// <param name="scene"></param> /// <returns></returns> public IEnumerable <IThing> SelectedThings(IGraphScene <IVisual, IVisualEdge> scene) { var visuals = scene.Selected.Elements; if (visuals.Count() == 0) { visuals = scene.Graph.Where(v => !(v is IVisualEdge)); } if (visuals.Count() == 0) { return(null); } IEnumerable <IThing> things = null; if (visuals.Count() == 1) { var thing = scene.Graph.ThingOf(visuals.First()); var digidoc = new DigidocSchema(scene.Graph.ThingGraph(), thing); if (digidoc.HasPages()) { things = digidoc.OrderedPages(); } } if (things == null) { things = visuals .OrderBy(v => v.Location, new PointComparer { Delta = 20 }) .Select(v => scene.Graph.ThingOf(v)); } return(things); }
public ActionResult Index(string id) { Trace.WriteLine("HomeController.Index({0})", id); ActionResult result = base.HttpNotFound("not found"); ViewBag.Message = id ?? "<null>"; ViewBag.Id = id; var things = Backend.ResolveRequest(id); if (things == null) { return(View("About", new HtmlContent { Description = "not found", Data = string.Format("{0}<br/>{1}", id, "not found") })); } Action <Content> setViewBag = content => { ViewBag.Title = content.Description; ViewBag.Id = content.Source; }; Func <IEnumerable <IThing>, ActionResult> linksOfThings = ts => View(Views.Hrefs, new Hrefs { Refs = Backend.HrefsOfThings(ts) }); Func <IThing, Content, ActionResult> contentAndLinks = (thing, c) => { var leafs = Backend.HrefsOfThings(Backend.Leafs(thing) .OrderBy(t => Backend.ThingDataToDisplay(t))) .ToArray(); var roots = Backend.HrefsOfThings(Backend.Roots(thing) .OrderBy(t => Backend.ThingDataToDisplay(t))) .ToArray(); return(View(Views.ContentAndLinks, new ContentAndLinks { Content = c, Leafs = leafs, Roots = roots })); }; Func <IThing, Content, ActionResult> digidoc = (thing, c) => { var doc = new DigidocSchema(Backend.ThingGraph, thing); var leafs = Backend.HrefsOfThings(doc.OrderedPages()); var roots = Backend.HrefsOfThings(Backend.Roots(thing).OrderBy(t => Backend.ThingDataToDisplay(t))); // TODO: what if pages are no images, but text or something else? return(View(Views.DigiDoc, new ContentAndLinks { Content = c, Leafs = leafs, Roots = roots })); }; Func <IThing, Content, ActionResult> sheet = (thing, c) => { var hrefsOf = Backend.VisualHrefsOf(thing as IStreamThing); var leafs = Backend.HrefsOfThings(Backend.Leafs(thing) .OrderBy(t => Backend.ThingDataToDisplay(t))) .ToArray(); var roots = Backend.HrefsOfThings(Backend.Roots(thing) .OrderBy(t => Backend.ThingDataToDisplay(t))) .ToArray(); return(View(Views.SheetContent, new VisualHrefContent { Hrefs = hrefsOf, Roots = roots, Description = c.Description, Leafs = leafs })); }; if (things.Count() == 1) { var thing = things.First(); if (thing is IStreamThing) { if (Backend.IsConvertibleToHtml(thing)) { var content = Backend.HtmlContent(thing as IStreamThing); setViewBag(content); result = contentAndLinks(thing, content); } else if (((StreamThing)thing).StreamType == ContentTypes.LimadaSheet) { var content = Backend.StreamContent(thing as StreamThing); setViewBag(content); result = sheet(thing, content); } else { var content = Backend.StreamContent(thing as StreamThing); setViewBag(content); result = File(content.Data, content.MimeType); } } else if (thing != null) { var content = new Content { Description = Backend.ThingToDisplay(thing).ToString(), Source = thing.Id.ToString("X16"), }; setViewBag(content); var doc = new DigidocSchema(Backend.ThingGraph, thing); if (doc.HasPages()) { result = digidoc(thing, content); } else { result = contentAndLinks(thing, content); } } } else if (things.Count() > 1) { var content = new Content { Description = id + " ...", Source = "", }; setViewBag(content); result = View(Views.ContentAndLinks, new ContentAndLinks { Content = content, Leafs = Backend.HrefsOfThings(things).OrderBy(l => l.Text), Roots = new Href[0] }); } return(result); }