Editor for content editing

This commit is contained in:
Kenn Jacobsen
2019-05-19 17:48:10 +02:00
parent 5cb847930d
commit 013bd2c424
6 changed files with 206 additions and 11 deletions
@@ -520,6 +520,20 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) {
});
},
getScaffoldByUdi: function (parentId, udi) {
return umbRequestHelper.resourcePromise(
$http.get(
umbRequestHelper.getApiUrl(
"contentApiBaseUrl",
"GetEmpty",
[{ udi: udi }, { parentId: parentId }])),
'Failed to retrieve data for empty content item with udi ' + udi)
.then(function (result) {
return $q.when(umbDataFormatter.formatContentGetData(result));
});
},
getBlueprintScaffold: function (parentId, blueprintId) {
return umbRequestHelper.resourcePromise(
@@ -1,7 +1,80 @@
angular.module("umbraco")
.controller("Umbraco.PropertyEditors.BlockEditor.PropertyEditorController", [
"$scope",
function ($scope) {
function BlockEditorPropertyEditorController($scope, contentResource, editorService) {
var vm = this;
vm.scaffolds = [];
vm.blocks = [];
vm.loading = true;
vm.sortableOptions = {
axis: "y",
cursor: "move",
handle: ".handle",
tolerance: 'pointer'
};
vm.add = add;
vm.edit = edit;
vm.remove = remove;
// it would be awesome if we could load all scaffolds in one go... however we need to have an eye out for performance,
// oddly enough it's been shown to actually be slower to load them all at once instead of one at a time
var scaffoldsLoaded = 0;
function init() {
$scope.model.value = $scope.model.value || [];
_.each($scope.model.config.blocks, function (blockConfig) {
contentResource.getScaffoldByUdi(-20, blockConfig.elementType).then(function (scaffold) {
if (scaffold.isElement) {
vm.scaffolds.push(scaffold);
}
scaffoldsLoaded++;
initIfAllScaffoldsHaveLoaded();
}, function (error) {
scaffoldsLoaded++;
initIfAllScaffoldsHaveLoaded();
});
});
}
function initIfAllScaffoldsHaveLoaded() {
// Initialize when all scaffolds have loaded
if ($scope.model.config.blocks.length === scaffoldsLoaded) {
vm.scaffolds = _.sortBy(vm.scaffolds, function (scaffold) {
return _.findIndex($scope.model.config.blocks, function (blockConfig) {
return blockConfig.elementType === scaffold.udi;
});
});
vm.loading = false;
}
]
);
}
function add(scaffold) {
var block = angular.copy(scaffold);
edit(block);
}
function edit(block) {
var options = {
node: block,
title: "TODO: Edit block title here",
view: "views/propertyeditors/blockeditor/blockeditor.editblock.html",
submit: function(model) {
if (vm.blocks.indexOf(block) < 0) {
vm.blocks.push(block);
}
editorService.close();
},
close: function() {
editorService.close();
}
};
editorService.open(options);
}
function remove(block) {
if (confirm("TODO: Are you sure?")) {
vm.blocks.splice(vm.blocks.indexOf(block), 1);
}
}
init();
}
angular.module("umbraco").controller("Umbraco.PropertyEditors.BlockEditor.PropertyEditorController", BlockEditorPropertyEditorController);
@@ -0,0 +1,25 @@
function BlockEditorEditBlockController($scope) {
var vm = this;
vm.submit = submit;
vm.close = close;
vm.content = $scope.model.node.variants[0];
function init() {
}
function submit() {
if($scope.model.submit) {
$scope.model.submit($scope.model);
}
}
function close() {
if($scope.model.close) {
$scope.model.close();
}
}
init();
}
angular.module("umbraco").controller("Umbraco.PropertyEditors.BlockEditor.EditBlockController", BlockEditorEditBlockController);
@@ -0,0 +1,38 @@
<div ng-controller="Umbraco.PropertyEditors.BlockEditor.EditBlockController as vm">
<umb-editor-view>
<umb-editor-header name="model.title"
name-locked="true"
hide-alias="true"
hide-icon="true"
hide-description="true">
</umb-editor-header>
<umb-editor-container>
<umb-load-indicator ng-if="vm.loading" />
<div ng-if="!loading">
<ng-form name="editBlockForm" val-form-manager>
<umb-tabbed-content content="vm.content" />
</ng-form>
</div>
</umb-editor-container>
<umb-editor-footer>
<umb-editor-footer-content-right>
<umb-button type="button"
button-style="link"
label-key="general_cancel"
shortcut="esc"
action="vm.close()">
</umb-button>
<umb-button type="button"
button-style="success"
label-key="general_ok"
action="vm.submit()">
</umb-button>
</umb-editor-footer-content-right>
</umb-editor-footer>
</umb-editor-view>
</div>
@@ -1,5 +1,28 @@
<div ng-controller="Umbraco.PropertyEditors.BlockEditor.PropertyEditorController">
<pre>
{{model.config | json}}
</pre>
<div ng-controller="Umbraco.PropertyEditors.BlockEditor.PropertyEditorController as vm">
<div style="position:relative" ng-if="vm.loading">
<umb-load-indicator />
</div>
<div ng-if="!vm.loading">
<div ui-sortable="vm.sortableOptions" ng-model="vm.blocks">
<div ng-repeat="block in vm.blocks">
<div style="cursor:pointer" ng-click="vm.edit(block)" class="di">
<i class="icon {{block.documentType.icon}}"></i>
</div>
<div style="cursor:pointer" ng-click="vm.remove(block)" class="di">
<i class="icon icon-trash"></i>
</div>
<div style="cursor:move" class="di handle">
<i class="icon icon-navigation"></i>
</div>
</div>
</div>
<div>
Add:
<div style="cursor:pointer" ng-click="vm.add(scaffold)" ng-repeat="scaffold in vm.scaffolds" class="di">
<i class="icon {{scaffold.documentType.icon}}"></i>
</div>
</div>
</div>
</div>
+23 -1
View File
@@ -354,12 +354,34 @@ namespace Umbraco.Web.Editors
throw new HttpResponseException(HttpStatusCode.NotFound);
}
return EmptyContent(parentId, contentType);
}
/// <summary>
/// Gets an empty content item for the
/// </summary>
/// <param name="udi"></param>
/// <param name="parentId"></param>
[OutgoingEditorModelEvent]
public ContentItemDisplay GetEmpty(GuidUdi udi, int parentId)
{
var contentType = Services.ContentTypeService.Get(udi.Guid);
if(contentType == null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
return EmptyContent(parentId, contentType);
}
private ContentItemDisplay EmptyContent(int parentId, IContentType contentType)
{
var emptyContent = Services.ContentService.Create("", parentId, contentType.Alias, Security.GetUserId().ResultOr(0));
var mapped = MapToDisplay(emptyContent);
// translate the content type name if applicable
mapped.ContentTypeName = Services.TextService.UmbracoDictionaryTranslate(mapped.ContentTypeName);
// if your user type doesn't have access to the Settings section it would not get this property mapped
if (mapped.DocumentType != null)
if(mapped.DocumentType != null)
mapped.DocumentType.Name = Services.TextService.UmbracoDictionaryTranslate(mapped.DocumentType.Name);
//remove the listview app if it exists