1
1
using Microsoft . AspNetCore . Http . Extensions ;
2
2
using Microsoft . AspNetCore . Mvc ;
3
+ using Microsoft . AspNetCore . Mvc . ModelBinding ;
4
+ using Microsoft . AspNetCore . Mvc . Rendering ;
5
+ using Microsoft . AspNetCore . Mvc . ViewFeatures ;
3
6
using Our . Umbraco . DocTypeGridEditor9 . Helpers ;
7
+ using Our . Umbraco . DocTypeGridEditor9 . Models ;
4
8
using Our . Umbraco . DocTypeGridEditor9 . Web . Models ;
5
9
using System ;
6
10
using System . Collections . Generic ;
15
19
using Umbraco . Cms . Core ;
16
20
using Umbraco . Cms . Core . Models ;
17
21
using Umbraco . Cms . Core . Models . PublishedContent ;
22
+ using Umbraco . Cms . Core . PropertyEditors ;
18
23
using Umbraco . Cms . Core . PublishedCache ;
19
24
using Umbraco . Cms . Core . Routing ;
20
25
using Umbraco . Cms . Core . Services ;
@@ -37,6 +42,10 @@ public class DocTypeGridEditorApiController : UmbracoAuthorizedJsonController
37
42
private readonly IPublishedContentQuery _contentQuery ;
38
43
private readonly IPublishedRouter _router ;
39
44
private readonly DocTypeGridEditorHelper _dtgeHelper ;
45
+ private readonly ServiceContext _serviceContext ;
46
+ private readonly IPublishedContentTypeFactory _publishedContentTypeFactory ;
47
+ private readonly IPublishedModelFactory _publishedModelFactory ;
48
+ private readonly PropertyEditorCollection _propertyEditorCollection ;
40
49
41
50
public DocTypeGridEditorApiController ( IUmbracoContextAccessor umbracoContext ,
42
51
IContentTypeService contentTypeService ,
@@ -45,6 +54,9 @@ public DocTypeGridEditorApiController(IUmbracoContextAccessor umbracoContext,
45
54
IShortStringHelper shortStringHelper ,
46
55
IPublishedContentQuery contentQuery ,
47
56
IPublishedRouter router ,
57
+ ServiceContext serviceContext ,
58
+ IPublishedContentTypeFactory publishedContentTypeFactory ,
59
+ PropertyEditorCollection propertyEditorCollection ,
48
60
DocTypeGridEditorHelper dtgeHelper )
49
61
{
50
62
_umbracoContext = umbracoContext ;
@@ -55,10 +67,13 @@ public DocTypeGridEditorApiController(IUmbracoContextAccessor umbracoContext,
55
67
_contentQuery = contentQuery ;
56
68
_router = router ;
57
69
_dtgeHelper = dtgeHelper ;
70
+ _serviceContext = serviceContext ;
71
+ _publishedContentTypeFactory = publishedContentTypeFactory ;
72
+ _propertyEditorCollection = propertyEditorCollection ;
58
73
}
59
74
60
75
[ HttpGet ]
61
- public object GetContentTypeAliasByGuid ( [ ModelBinder ] Guid guid )
76
+ public object GetContentTypeAliasByGuid ( [ FromQuery ] Guid guid )
62
77
{
63
78
return new
64
79
{
@@ -67,7 +82,7 @@ public object GetContentTypeAliasByGuid([ModelBinder] Guid guid)
67
82
}
68
83
69
84
[ HttpGet ]
70
- public IEnumerable < object > GetContentTypesOld ( string [ ] allowedContentTypes )
85
+ public IEnumerable < object > GetContentTypes ( [ FromQuery ] string [ ] allowedContentTypes )
71
86
{
72
87
var allContentTypes = _contentTypeService . GetAll ( ) . ToList ( ) ;
73
88
var contentTypes = allContentTypes
@@ -96,35 +111,7 @@ public IEnumerable<object> GetContentTypesOld(string[] allowedContentTypes)
96
111
}
97
112
98
113
[ HttpGet ]
99
- public IEnumerable < object > GetContentTypes ( )
100
- {
101
- var allContentTypes = _contentTypeService . GetAll ( ) . ToList ( ) ;
102
- var contentTypes = allContentTypes
103
- . Where ( x => x . IsElement && x . VariesByCulture ( ) == false )
104
- . OrderBy ( x => x . Name )
105
- . ToList ( ) ;
106
-
107
- var blueprints = _contentService . GetBlueprintsForContentTypes ( contentTypes . Select ( x => x . Id ) . ToArray ( ) ) . ToArray ( ) ;
108
-
109
- return contentTypes
110
- . Select ( x => new
111
- {
112
- id = x . Id ,
113
- guid = x . Key ,
114
- name = x . Name ,
115
- alias = x . Alias ,
116
- description = x . Description ,
117
- icon = x . Icon ,
118
- blueprints = blueprints . Where ( bp => bp . ContentTypeId == x . Id ) . Select ( bp => new
119
- {
120
- id = bp . Id ,
121
- name = bp . Name
122
- } )
123
- } ) ;
124
- }
125
-
126
- [ HttpGet ]
127
- public object GetContentType ( string contentTypeAlias )
114
+ public object GetContentType ( [ FromQuery ] string contentTypeAlias )
128
115
{
129
116
Guid docTypeGuid ;
130
117
if ( Guid . TryParse ( contentTypeAlias , out docTypeGuid ) )
@@ -140,7 +127,7 @@ public object GetContentType(string contentTypeAlias)
140
127
}
141
128
142
129
[ HttpGet ]
143
- public object GetDataTypePreValues ( string dtdId )
130
+ public object GetDataTypePreValues ( [ FromQuery ] string dtdId )
144
131
{
145
132
Guid guidDtdId ;
146
133
int intDtdId ;
@@ -173,7 +160,7 @@ public object GetDataTypePreValues(string dtdId)
173
160
}
174
161
175
162
[ HttpPost ]
176
- public HttpResponseMessage GetPreviewMarkup ( [ FromBody ] PreviewData data , int pageId )
163
+ public PartialViewResult GetPreviewMarkup ( [ FromForm ] PreviewData data , [ FromQuery ] int pageId )
177
164
{
178
165
var page = default ( IPublishedContent ) ;
179
166
@@ -185,7 +172,7 @@ public HttpResponseMessage GetPreviewMarkup([FromBody] PreviewData data, int pag
185
172
if ( page == null )
186
173
{
187
174
// If unpublished, then fake PublishedContent
188
- // page = new UnpublishedContent(pageId, Services); TODO: UnpublishedContent
175
+ page = new UnpublishedContent ( pageId , _contentService , _contentTypeService , _dataTypeService , _propertyEditorCollection , _publishedContentTypeFactory ) ;
189
176
}
190
177
}
191
178
@@ -224,19 +211,18 @@ public HttpResponseMessage GetPreviewMarkup([FromBody] PreviewData data, int pag
224
211
ViewPath = data . ViewPath
225
212
} ;
226
213
214
+
227
215
// Render view
216
+
228
217
var partialName = "~/App_Plugins/DocTypeGridEditor/Render/DocTypeGridEditorPreviewer.cshtml" ;
229
- var markup = Helpers . ViewHelper . RenderPartial ( partialName , model , HttpContext , _umbracoContext . UmbracoContext ) ;
230
218
231
- // Return response
232
- var response = new HttpResponseMessage
219
+ var viewData = new ViewDataDictionary ( new EmptyModelMetadataProvider ( ) , new ModelStateDictionary ( ) ) ;
220
+ viewData . Model = model ;
221
+ return new PartialViewResult ( )
233
222
{
234
- Content = new StringContent ( markup ?? string . Empty )
223
+ ViewName = partialName ,
224
+ ViewData = viewData
235
225
} ;
236
-
237
- response . Content . Headers . ContentType = new MediaTypeHeaderValue ( MediaTypeNames . Text . Html ) ;
238
-
239
- return response ;
240
226
}
241
227
}
242
228
}
0 commit comments