Skip to content
This repository was archived by the owner on Feb 10, 2024. It is now read-only.

Commit ac73f60

Browse files
committed
fix viewhelper
1 parent e9af553 commit ac73f60

File tree

3 files changed

+9
-62
lines changed

3 files changed

+9
-62
lines changed

src/Our.Umbraco.DocTypeGridEditor9/Web/Extensions/HtmlHelperExtensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ public static IHtmlContent RenderDocTypeGridEditorItem(
106106
if (string.IsNullOrWhiteSpace(viewPath) == false)
107107
{
108108
var fullViewPath = $"{viewPath}{editorAlias}.cshtml";
109-
//if (ViewHelper.ViewExists(helper.ViewContext, fullViewPath, true))
110-
//{
111-
// return helper.PartialAsync(fullViewPath, content).Result;
112-
//}
109+
if (ViewHelper.ViewExists(helper.ViewContext, fullViewPath, true))
110+
{
111+
return helper.PartialAsync(fullViewPath, content).Result;
112+
}
113113

114114
fullViewPath = $"{viewPath}{content.ContentType.Alias}.cshtml";
115115
if (ViewHelper.ViewExists(helper.ViewContext, fullViewPath, true))

src/Our.Umbraco.DocTypeGridEditor9/Web/Helpers/ViewHelper.cs

Lines changed: 3 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -16,64 +16,11 @@ namespace Our.Umbraco.DocTypeGridEditor9.Web.Helpers
1616
{
1717
internal static class ViewHelper
1818
{
19-
private class DummyController : Controller { }
20-
21-
public static string RenderPartial(string partialName, object model, HttpContext httpContext = null, IUmbracoContext umbracoContext = null)
22-
{
23-
using (var sw = new StringWriter())
24-
{
25-
if (httpContext == null)
26-
return null;
27-
// TODO: Can we make a HttpContext?
28-
// httpContext = new HttpContextWrapper(HttpContext.Current);
29-
30-
if (umbracoContext == null)
31-
return null;
32-
// TODO: Can we get the UmbracoContext?
33-
// umbracoContext = Current.UmbracoContext;
34-
35-
return null;
36-
/*
37-
* TODO: Don't know how to do the rest
38-
var routeData = new RouteData();
39-
routeData.Values.Add("controller", "DummyController");
40-
41-
if (umbracoContext.PublishedRequest != null)
42-
{
43-
routeData.DataTokens[Constants.UmbracoRouteDefinitionDataToken] = new RouteDefinition
44-
{
45-
PublishedRequest = umbracoContext.PublishedRequest
46-
};
47-
}
48-
49-
var controllerContext = new ControllerContext(new RequestContext(httpContext, routeData), new DummyController());
50-
51-
var viewResult = ViewEngines.Engines.FindPartialView(controllerContext, partialName);
52-
if (viewResult.View == null)
53-
{
54-
Current.Logger.Warn(typeof(ViewHelper), $"No view found for partial '{partialName}'");
55-
return null;
56-
}
57-
58-
viewResult.View.Render(new ViewContext(controllerContext, viewResult.View, new ViewDataDictionary { Model = model }, new TempDataDictionary(), sw), sw);
59-
60-
return sw.ToString();
61-
*/
62-
}
63-
}
64-
6519
public static bool ViewExists(ViewContext viewContext, string viewName, bool isPartial = false)
6620
{
67-
/* TODO: This doesn't work
68-
var result = isPartial == false
69-
? viewContext..Engines.FindView(viewContext, viewName, null)
70-
: ViewEngines.Engines.FindPartialView(viewContext, viewName);
71-
72-
if (result.View != null)
73-
return true;
74-
75-
return false;*/
76-
return true;
21+
var viewEngine = viewContext.HttpContext.RequestServices.GetRequiredService<ICompositeViewEngine>();
22+
var result = viewEngine.GetView(null, viewName, true).Success || viewEngine.GetView(null, viewName, false).Success;
23+
return result;
7724
}
7825
}
7926
}

src/Our.Umbraco.DocTypeGridEditor9/Web/UI/App_Plugins/DocTypeGridEditor/package.manifest

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
"alias": "docType",
66
"view": "/App_Plugins/DocTypeGridEditor/Views/doctypegrideditor.html",
77
"render": "/App_Plugins/DocTypeGridEditor/Render/DocTypeGridEditor.cshtml",
8-
"icon": "icon-item-arrangement",
8+
"icon": "icon-science",
99
"config": {
1010
"allowedDocTypes": [],
1111
"nameTemplate": "",
12-
"enablePreview": false,
12+
"enablePreview": true,
1313
"viewPath": "/Views/Partials/Grid/Editors/DocTypeGridEditor/",
1414
"previewViewPath": "/Views/Partials/Grid/Editors/DocTypeGridEditor/Previews/",
1515
"previewCssFilePath": "",

0 commit comments

Comments
 (0)