Got media creation working and fixed updating node names.
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
<div ng-controller="Umbraco.Editors.GoogleMapsController" class="span7">
|
||||
<div class="" style="height: 200px;" id="{{model.alias}}_map"></div>
|
||||
<div class="" style="height: 400px;" id="{{model.alias}}_map"></div>
|
||||
</div>
|
||||
@@ -11,7 +11,7 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) {
|
||||
}
|
||||
/** internal method to get the api url */
|
||||
function getEmptyContentUrl(contentTypeAlias, parentId) {
|
||||
return Umbraco.Sys.ServerVariables.contentApiBaseUrl + "GetEmptyContent?contentTypeAlias=" + contentTypeAlias + "&parentId=" + parentId;
|
||||
return Umbraco.Sys.ServerVariables.contentApiBaseUrl + "GetEmpty?contentTypeAlias=" + contentTypeAlias + "&parentId=" + parentId;
|
||||
}
|
||||
/** internal method to get the api url for publishing */
|
||||
function getSaveUrl() {
|
||||
@@ -49,7 +49,7 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) {
|
||||
|
||||
/** returns an empty content object which can be persistent on the content service
|
||||
requires the parent id and the alias of the content type to base the scaffold on */
|
||||
getContentScaffold: function (parentId, alias) {
|
||||
getScaffold: function (parentId, alias) {
|
||||
|
||||
var deferred = $q.defer();
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ function contentTypeResource($q, $http) {
|
||||
|
||||
/** internal method to get the api url */
|
||||
function getChildContentTypesUrl(contentId) {
|
||||
return Umbraco.Sys.ServerVariables.contentTypeApiBaseUrl + "GetAllowedChildrenForContent?contentId=" + contentId;
|
||||
return Umbraco.Sys.ServerVariables.contentTypeApiBaseUrl + "GetAllowedChildren?contentId=" + contentId;
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -9,6 +9,12 @@ function mediaResource($q, $http, umbDataFormatter, umbRequestHelper) {
|
||||
function getMediaUrl(contentId) {
|
||||
return Umbraco.Sys.ServerVariables.mediaApiBaseUrl + "GetById?id=" + contentId;
|
||||
}
|
||||
|
||||
/** internal method to get the api url */
|
||||
function getEmptyMediaUrl(contentTypeAlias, parentId) {
|
||||
return Umbraco.Sys.ServerVariables.mediaApiBaseUrl + "GetEmpty?contentTypeAlias=" + contentTypeAlias + "&parentId=" + parentId;
|
||||
}
|
||||
|
||||
/** internal method to get the api url */
|
||||
function getRootMediaUrl() {
|
||||
return Umbraco.Sys.ServerVariables.mediaApiBaseUrl + "GetRootMedia";
|
||||
@@ -54,6 +60,32 @@ function mediaResource($q, $http, umbDataFormatter, umbRequestHelper) {
|
||||
return deferred.promise;
|
||||
},
|
||||
|
||||
/** returns an empty content object which can be persistent on the content service
|
||||
requires the parent id and the alias of the content type to base the scaffold on */
|
||||
getScaffold: function (parentId, alias) {
|
||||
|
||||
var deferred = $q.defer();
|
||||
|
||||
//go and get the data
|
||||
$http.get(getEmptyMediaUrl(alias, parentId)).
|
||||
success(function (data, status, headers, config) {
|
||||
//set the first tab to active
|
||||
_.each(data.tabs, function (item) {
|
||||
item.active = false;
|
||||
});
|
||||
if (data.tabs.length > 0) {
|
||||
data.tabs[0].active = true;
|
||||
}
|
||||
|
||||
deferred.resolve(data);
|
||||
}).
|
||||
error(function (data, status, headers, config) {
|
||||
deferred.reject('Failed to retreive data for empty content item type ' + alias);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
},
|
||||
|
||||
rootMedia: function () {
|
||||
|
||||
var deferred = $q.defer();
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* @ngdoc factory
|
||||
* @name umbraco.resources.mediaTypeResource
|
||||
* @description Loads in data for content types
|
||||
**/
|
||||
function mediaTypeResource($q, $http) {
|
||||
|
||||
/** internal method to get the api url */
|
||||
function getChildContentTypesUrl(contentId) {
|
||||
return Umbraco.Sys.ServerVariables.mediaTypeApiBaseUrl + "GetAllowedChildren?contentId=" + contentId;
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
//return all types allowed under given document
|
||||
getAllowedTypes: function (contentId) {
|
||||
|
||||
var deferred = $q.defer();
|
||||
|
||||
//go and get the tree data
|
||||
$http.get(getChildContentTypesUrl(contentId)).
|
||||
success(function (data, status, headers, config) {
|
||||
deferred.resolve(data);
|
||||
}).
|
||||
error(function (data, status, headers, config) {
|
||||
deferred.reject('Failed to retreive data for media id ' + contentId);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
angular.module('umbraco.resources').factory('mediaTypeResource', mediaTypeResource);
|
||||
@@ -4,7 +4,7 @@ angular.module("umbraco")
|
||||
|
||||
if ($routeParams.create) {
|
||||
|
||||
contentResource.getContentScaffold($routeParams.id, $routeParams.doctype)
|
||||
contentResource.getScaffold($routeParams.id, $routeParams.doctype)
|
||||
.then(function (data) {
|
||||
$scope.content = data;
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
function mediaCreateController ($scope, $routeParams,contentTypeResource) {
|
||||
$scope.allowedTypes = contentTypeResource.getAllowedTypes($scope.currentNode.id);
|
||||
function mediaCreateController ($scope, $routeParams,mediaTypeResource) {
|
||||
$scope.allowedTypes = mediaTypeResource.getAllowedTypes($scope.currentNode.id);
|
||||
}
|
||||
|
||||
angular.module('umbraco')
|
||||
|
||||
@@ -2,7 +2,7 @@ function mediaEditController($scope, $routeParams, mediaResource, notificationsS
|
||||
|
||||
if ($routeParams.create) {
|
||||
|
||||
mediaResource.getContentScaffold($routeParams.id, $routeParams.doctype)
|
||||
mediaResource.getScaffold($routeParams.id, $routeParams.doctype)
|
||||
.then(function (data) {
|
||||
$scope.content = data;
|
||||
});
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
|
||||
<div ng-show="persistedFiles.length > 0">
|
||||
<p>Current files</p>
|
||||
<ul>
|
||||
<li ng-repeat="file in persistedFiles">
|
||||
<ul class="thumbnails">
|
||||
<li class="thumbnail" ng-repeat="file in persistedFiles">
|
||||
<div ng-switch on="file.isImage" >
|
||||
<img ng-src="{{getThumbnail(file)}}" ng-switch-when="true" alt="{{file.file}}"/>
|
||||
<span ng-switch-default>{{file.file}}</span>
|
||||
|
||||
@@ -50,7 +50,8 @@ namespace Umbraco.Web.Editors
|
||||
{"contentApiBaseUrl", Url.GetUmbracoApiService<ContentController>("PostSave").TrimEnd("PostSave")},
|
||||
{"mediaApiBaseUrl", Url.GetUmbracoApiService<MediaController>("GetRootMedia").TrimEnd("GetRootMedia")},
|
||||
{"treeApplicationApiBaseUrl", Url.GetUmbracoApiService<ApplicationTreeApiController>("GetTreeData").TrimEnd("GetTreeData")},
|
||||
{"contentTypeApiBaseUrl", Url.GetUmbracoApiService<ContentTypeApiController>("GetAllowedChildrenForContent").TrimEnd("GetAllowedChildrenForContent")}
|
||||
{"contentTypeApiBaseUrl", Url.GetUmbracoApiService<ContentTypeApiController>("GetAllowedChildren").TrimEnd("GetAllowedChildren")},
|
||||
{"mediaTypeApiBaseUrl", Url.GetUmbracoApiService<MediaTypeApiController>("GetAllowedChildren").TrimEnd("GetAllowedChildren")}
|
||||
};
|
||||
|
||||
return JavaScript(ServerVariablesParser.Parse(d));
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace Umbraco.Web.Editors
|
||||
/// <param name="contentTypeAlias"></param>
|
||||
/// <param name="parentId"></param>
|
||||
/// <returns></returns>
|
||||
public ContentItemDisplay GetEmptyContent(string contentTypeAlias, int parentId)
|
||||
public ContentItemDisplay GetEmpty(string contentTypeAlias, int parentId)
|
||||
{
|
||||
var contentType = Services.ContentTypeService.GetContentType(contentTypeAlias);
|
||||
if (contentType == null)
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace Umbraco.Web.Editors
|
||||
/// Returns the allowed child content type objects for the content item id passed in
|
||||
/// </summary>
|
||||
/// <param name="contentId"></param>
|
||||
public IEnumerable<object> GetAllowedChildrenForContent(int contentId)
|
||||
public IEnumerable<object> GetAllowedChildren(int contentId)
|
||||
{
|
||||
var contentItem = Services.ContentService.GetById(contentId);
|
||||
if (contentItem == null)
|
||||
@@ -52,4 +52,50 @@ namespace Umbraco.Web.Editors
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An API controller used for dealing with content types
|
||||
/// </summary>
|
||||
public class MediaTypeApiController : UmbracoAuthorizedApiController
|
||||
{
|
||||
private readonly MediaTypeModelMapper _mediaTypeModelMapper;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
public MediaTypeApiController()
|
||||
: this(UmbracoContext.Current, new MediaTypeModelMapper(UmbracoContext.Current.Application))
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="umbracoContext"></param>
|
||||
/// <param name="mediaModelMapper"></param>
|
||||
internal MediaTypeApiController(UmbracoContext umbracoContext, MediaTypeModelMapper mediaModelMapper)
|
||||
: base(umbracoContext)
|
||||
{
|
||||
_mediaTypeModelMapper = mediaModelMapper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the allowed child content type objects for the content item id passed in
|
||||
/// </summary>
|
||||
/// <param name="contentId"></param>
|
||||
public IEnumerable<object> GetAllowedChildren(int contentId)
|
||||
{
|
||||
var contentItem = Services.MediaService.GetById(contentId);
|
||||
if (contentItem == null)
|
||||
{
|
||||
throw new HttpResponseException(HttpStatusCode.NotFound);
|
||||
}
|
||||
|
||||
|
||||
return contentItem.ContentType.AllowedContentTypes
|
||||
.Select(x => Services.ContentTypeService.GetMediaType(x.Id.Value))
|
||||
.Select(x => _mediaTypeModelMapper.ToMediaTypeBasic(x));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Web.Http;
|
||||
@@ -52,6 +53,24 @@ namespace Umbraco.Web.Editors
|
||||
_mediaModelMapper = mediaModelMapper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an empty content item for the
|
||||
/// </summary>
|
||||
/// <param name="contentTypeAlias"></param>
|
||||
/// <param name="parentId"></param>
|
||||
/// <returns></returns>
|
||||
public MediaItemDisplay GetEmpty(string contentTypeAlias, int parentId)
|
||||
{
|
||||
var contentType = Services.ContentTypeService.GetMediaType(contentTypeAlias);
|
||||
if (contentType == null)
|
||||
{
|
||||
throw new HttpResponseException(HttpStatusCode.NotFound);
|
||||
}
|
||||
|
||||
var emptyContent = new Umbraco.Core.Models.Media("Empty", parentId, contentType);
|
||||
return _mediaModelMapper.ToMediaItemDisplay(emptyContent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the content json for the content id
|
||||
/// </summary>
|
||||
@@ -107,6 +126,9 @@ namespace Umbraco.Web.Editors
|
||||
|
||||
//Now, we just need to save the data
|
||||
|
||||
contentItem.PersistedContent.Name = contentItem.Name;
|
||||
//TODO: We'll need to save the new template, publishat, etc... values here
|
||||
|
||||
//Save the property values (for properties that have a valid editor ... not legacy)
|
||||
foreach (var p in contentItem.ContentDto.Properties.Where(x => x.PropertyEditor != null))
|
||||
{
|
||||
|
||||
@@ -149,7 +149,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
var legacyResult = new TContentProperty
|
||||
{
|
||||
Id = property.Id,
|
||||
Value = property.Value.ToString(),
|
||||
Value = property.Value == null ? "" : property.Value.ToString(),
|
||||
Alias = property.Alias
|
||||
};
|
||||
if (callback != null) callback(legacyResult, property, null);
|
||||
|
||||
@@ -25,4 +25,26 @@ namespace Umbraco.Web.Models.Mapping
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
internal class MediaTypeModelMapper
|
||||
{
|
||||
private readonly ApplicationContext _applicationContext;
|
||||
|
||||
public MediaTypeModelMapper(ApplicationContext applicationContext)
|
||||
{
|
||||
_applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
public ContentTypeBasic ToMediaTypeBasic(IMediaType contentType)
|
||||
{
|
||||
return new ContentTypeBasic
|
||||
{
|
||||
Alias = contentType.Alias,
|
||||
Id = contentType.Id,
|
||||
Description = contentType.Description,
|
||||
Icon = contentType.Icon,
|
||||
Name = contentType.Name
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -135,18 +135,30 @@ namespace Umbraco.Web.WebApi.Binders
|
||||
model.PersistedContent = CreateNew(model);
|
||||
}
|
||||
|
||||
model.ContentDto = Map(model);
|
||||
//we will now assign all of the values in the 'save' model to the DTO object
|
||||
foreach (var p in model.Properties)
|
||||
{
|
||||
model.ContentDto.Properties.Single(x => x.Id == p.Id).Value = p.Value;
|
||||
}
|
||||
|
||||
//create the dto from the persisted model
|
||||
model.ContentDto = MapFromPersisted(model);
|
||||
|
||||
//now map all of the saved values to the dto
|
||||
MapPropertyValuesFromSaved(model, model.ContentDto);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// we will now assign all of the values in the 'save' model to the DTO object
|
||||
/// </summary>
|
||||
/// <param name="saveModel"></param>
|
||||
/// <param name="dto"></param>
|
||||
private static void MapPropertyValuesFromSaved(ContentItemSave<TPersisted> saveModel, ContentItemDto<TPersisted> dto)
|
||||
{
|
||||
foreach (var p in saveModel.Properties)
|
||||
{
|
||||
dto.Properties.Single(x => x.Alias == p.Alias).Value = p.Value;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract TPersisted GetExisting(ContentItemSave<TPersisted> model);
|
||||
protected abstract TPersisted CreateNew(ContentItemSave<TPersisted> model);
|
||||
protected abstract ContentItemDto<TPersisted> Map(ContentItemSave<TPersisted> model);
|
||||
protected abstract ContentItemDto<TPersisted> MapFromPersisted(ContentItemSave<TPersisted> model);
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ namespace Umbraco.Web.WebApi.Binders
|
||||
return new Content(model.Name, model.ParentId, contentType);
|
||||
}
|
||||
|
||||
protected override ContentItemDto<IContent> Map(ContentItemSave<IContent> model)
|
||||
protected override ContentItemDto<IContent> MapFromPersisted(ContentItemSave<IContent> model)
|
||||
{
|
||||
return _contentModelMapper.ToContentItemDto(model.PersistedContent);
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace Umbraco.Web.WebApi.Binders
|
||||
return new Core.Models.Media(model.Name, model.ParentId, contentType);
|
||||
}
|
||||
|
||||
protected override ContentItemDto<IMedia> Map(ContentItemSave<IMedia> model)
|
||||
protected override ContentItemDto<IMedia> MapFromPersisted(ContentItemSave<IMedia> model)
|
||||
{
|
||||
return _mediaModelMapper.ToMediaItemDto(model.PersistedContent);
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ namespace Umbraco.Web.WebApi.Filters
|
||||
}
|
||||
|
||||
//get the posted value for this property
|
||||
var postedValue = postedItem.Properties.Single(x => x.Id == p.Id).Value;
|
||||
var postedValue = postedItem.Properties.Single(x => x.Alias == p.Alias).Value;
|
||||
|
||||
//get the pre-values for this property
|
||||
var preValues = _applicationContext.Services.DataTypeService.GetPreValueAsString(p.DataType.Id);
|
||||
|
||||
Reference in New Issue
Block a user