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

Commit ccce292

Browse files
Added logic to fetch doc types icon for the editor preview for when live preview is disabled, at least the icon can provide context.
1 parent 7a8c697 commit ccce292

File tree

6 files changed

+31
-4
lines changed

6 files changed

+31
-4
lines changed

Package/Doc_Type_Grid_Editor_0.1.zip

298 Bytes
Binary file not shown.

Src/Our.Umbraco.DocTypeGridEditor/Models/DetachedPublishedProperty.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public string PropertyTypeAlias {
3838

3939
public bool HasValue
4040
{
41-
get { return DataValue.ToString().Trim().Length > 0; }
41+
get { return DataValue != null && DataValue.ToString().Trim().Length > 0; }
4242
}
4343

4444
public object DataValue { get { return _rawValue; } }

Src/Our.Umbraco.DocTypeGridEditor/Web/Controllers/DocTypeGridEditorApiController.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Text.RegularExpressions;
5+
using System.Web.Configuration;
56
using Our.Umbraco.DocTypeGridEditor.Extensions;
67
using Umbraco.Core.Models;
78
using Umbraco.Core.PropertyEditors;
@@ -38,6 +39,17 @@ public IEnumerable<object> GetContentTypes([System.Web.Http.ModelBinding.ModelBi
3839
});
3940
}
4041

42+
[System.Web.Http.HttpGet]
43+
public object GetContentTypeIcon([System.Web.Http.ModelBinding.ModelBinder] Guid guid)
44+
{
45+
var contentTypeAlias = Services.ContentTypeService.GetAliasByGuid(guid);
46+
var contentType = Services.ContentTypeService.GetContentType(contentTypeAlias);
47+
return new
48+
{
49+
icon = contentType != null ? contentType.Icon : ""
50+
};
51+
}
52+
4153
[System.Web.Http.HttpGet]
4254
public object GetDataTypePreValues(string dtdId)
4355
{

Src/Our.Umbraco.DocTypeGridEditor/Web/UI/App_Plugins/DocTypeGridEditor/Js/doctypegrideditor.controllers.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
function ($scope, $rootScope, $timeout, $routeParams, dtgeDialogService, dtgeResources) {
1111

1212
$scope.title = "Click to insert item";
13+
$scope.icon = "icon-item-arrangement";
1314

1415
$scope.setValue = function (data) {
1516
$scope.control.value = data;
@@ -19,6 +20,13 @@
1920
if ("name" in $scope.control.value.value && $scope.control.value.value.name) {
2021
$scope.title = $scope.control.value.value.name;
2122
}
23+
if ("docType" in $scope.control.value && $scope.control.value.docType) {
24+
dtgeResources.getContentTypeIcon($scope.control.value.docType).then(function (data2) {
25+
if (data2.icon) {
26+
$scope.icon = data2.icon;
27+
}
28+
});
29+
}
2230
};
2331

2432
$scope.setDocType = function () {

Src/Our.Umbraco.DocTypeGridEditor/Web/UI/App_Plugins/DocTypeGridEditor/Js/doctypegrideditor.resources.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
var url = "/umbraco/backoffice/DocTypeGridEditorApi/DocTypeGridEditorApi/GetContentTypeAliasByGuid?guid=" + guid;
66
return umbRequestHelper.resourcePromise(
77
$http.get(url),
8-
'Failed to retrieve datatype alias by guid'
8+
'Failed to retrieve content type alias by guid'
99
);
1010
},
1111
getContentTypes: function (allowedContentTypes) {
@@ -17,7 +17,14 @@
1717
}
1818
return umbRequestHelper.resourcePromise(
1919
$http.get(url),
20-
'Failed to retrieve datatypes'
20+
'Failed to retrieve content types'
21+
);
22+
},
23+
getContentTypeIcon: function (guid) {
24+
var url = "/umbraco/backoffice/DocTypeGridEditorApi/DocTypeGridEditorApi/GetContentTypeIcon?guid=" + guid;
25+
return umbRequestHelper.resourcePromise(
26+
$http.get(url),
27+
'Failed to retrieve content type icon'
2128
);
2229
},
2330
getDataTypePreValues: function (dtdId) {

Src/Our.Umbraco.DocTypeGridEditor/Web/UI/App_Plugins/DocTypeGridEditor/Views/doctypegrideditor.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<div class="usky-editor-placeholder" ng-click="setDocType()">
44
<div ng-if="!preview">
5-
<i class="icon icon-item-arrangement"></i>
5+
<i class="icon {{icon}}"></i>
66
<div class="help-text">{{title}}</div>
77
</div>
88
<div ng-if="preview">

0 commit comments

Comments
 (0)