Added support for segments to File Uploads (#8070)
This commit is contained in:
@@ -16,6 +16,11 @@
|
||||
/// </summary>
|
||||
public string Culture { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// When dealing with content variants, this is the segment for the variant
|
||||
/// </summary>
|
||||
public string Segment { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// An array of metadata that is parsed out from the file info posted to the server which is set on the client.
|
||||
/// </summary>
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
fileManager.setFiles({
|
||||
propertyAlias: vm.propertyAlias,
|
||||
culture: vm.culture,
|
||||
segment: vm.segment,
|
||||
files: []
|
||||
});
|
||||
//clear the current files
|
||||
@@ -92,6 +93,11 @@
|
||||
vm.culture = null;
|
||||
}
|
||||
|
||||
//normalize segment to null if it's not there
|
||||
if (!vm.segment) {
|
||||
vm.segment = null;
|
||||
}
|
||||
|
||||
// TODO: need to figure out what we can do for things like Nested Content
|
||||
|
||||
var existingClientFiles = checkPendingClientFiles();
|
||||
@@ -134,11 +140,16 @@
|
||||
vm.culture = null;
|
||||
}
|
||||
|
||||
//normalize segment to null if it's not there
|
||||
if (!vm.segment) {
|
||||
vm.segment = null;
|
||||
}
|
||||
|
||||
//check the file manager to see if there's already local files pending for this editor
|
||||
var existingClientFiles = _.map(
|
||||
_.filter(fileManager.getFiles(),
|
||||
function (f) {
|
||||
return f.alias === vm.propertyAlias && f.culture === vm.culture;
|
||||
return f.alias === vm.propertyAlias && f.culture === vm.culture && f.segment === vm.segment;
|
||||
}),
|
||||
function (f) {
|
||||
return f.file;
|
||||
@@ -264,7 +275,8 @@
|
||||
fileManager.setFiles({
|
||||
propertyAlias: vm.propertyAlias,
|
||||
files: args.files,
|
||||
culture: vm.culture
|
||||
culture: vm.culture,
|
||||
segment: vm.segment
|
||||
});
|
||||
|
||||
updateModelFromSelectedFiles(args.files).then(function(newVal) {
|
||||
@@ -287,6 +299,7 @@
|
||||
templateUrl: 'views/components/upload/umb-property-file-upload.html',
|
||||
bindings: {
|
||||
culture: "@?",
|
||||
segment: "@?",
|
||||
propertyAlias: "@",
|
||||
value: "<",
|
||||
hideSelection: "<",
|
||||
|
||||
@@ -39,18 +39,22 @@ function fileManager($rootScope) {
|
||||
args.culture = null;
|
||||
}
|
||||
|
||||
if (!args.segment) {
|
||||
args.segment = null;
|
||||
}
|
||||
|
||||
var metaData = [];
|
||||
if (Utilities.isArray(args.metaData)) {
|
||||
metaData = args.metaData;
|
||||
}
|
||||
|
||||
//this will clear the files for the current property/culture and then add the new ones for the current property
|
||||
//this will clear the files for the current property/culture/segment and then add the new ones for the current property
|
||||
fileCollection = _.reject(fileCollection, function (item) {
|
||||
return item.alias === args.propertyAlias && (!args.culture || args.culture === item.culture);
|
||||
return item.alias === args.propertyAlias && (!args.culture || args.culture === item.culture) && (!args.segment || args.segment === item.segment);
|
||||
});
|
||||
for (var i = 0; i < args.files.length; i++) {
|
||||
//save the file object to the files collection
|
||||
fileCollection.push({ alias: args.propertyAlias, file: args.files[i], culture: args.culture, metaData: metaData });
|
||||
fileCollection.push({ alias: args.propertyAlias, file: args.files[i], culture: args.culture, segment: args.segment, metaData: metaData });
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -252,12 +252,13 @@ function umbRequestHelper($http, $q, notificationsService, eventsService, formHe
|
||||
for (var f in args.files) {
|
||||
//each item has a property alias and the file object, we'll ensure that the alias is suffixed to the key
|
||||
// so we know which property it belongs to on the server side
|
||||
var fileKey = "file_" + args.files[f].alias + "_" + (args.files[f].culture ? args.files[f].culture : "");
|
||||
var file = args.files[f];
|
||||
var fileKey = "file_" + file.alias + "_" + (file.culture ? file.culture : "") + "_" + (file.segment ? file.segment : "");
|
||||
|
||||
if (Utilities.isArray(args.files[f].metaData) && args.files[f].metaData.length > 0) {
|
||||
fileKey += ("_" + args.files[f].metaData.join("_"));
|
||||
if (Utilities.isArray(file.metaData) && file.metaData.length > 0) {
|
||||
fileKey += ("_" + file.metaData.join("_"));
|
||||
}
|
||||
formData.append(fileKey, args.files[f].file);
|
||||
formData.append(fileKey, file.file);
|
||||
}
|
||||
}).then(function (response) {
|
||||
//success callback
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
fileManager.setFiles({
|
||||
propertyAlias: $scope.model.alias,
|
||||
culture: $scope.model.culture,
|
||||
segment: $scope.model.segment,
|
||||
files: []
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<div ng-controller="Umbraco.PropertyEditors.FileUploadController">
|
||||
<umb-property-file-upload culture="{{model.culture}}"
|
||||
segment="{{model.segment}}"
|
||||
property-alias="{{model.alias}}"
|
||||
value="model.value"
|
||||
required="model.validation.mandatory"
|
||||
|
||||
@@ -55,6 +55,7 @@ angular.module('umbraco')
|
||||
fileManager.setFiles({
|
||||
propertyAlias: $scope.model.alias,
|
||||
culture: $scope.model.culture,
|
||||
segment: $scope.model.segment,
|
||||
files: []
|
||||
});
|
||||
}
|
||||
@@ -189,6 +190,7 @@ angular.module('umbraco')
|
||||
fileManager.setFiles({
|
||||
propertyAlias: $scope.model.alias,
|
||||
culture: $scope.model.culture,
|
||||
segment: $scope.model.segment,
|
||||
files: []
|
||||
});
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
<ng-form name="imageCropperForm">
|
||||
<umb-property-file-upload culture="{{model.culture}}"
|
||||
segment="{{model.segment}}"
|
||||
property-alias="{{model.alias}}"
|
||||
value="model.value.src"
|
||||
required="model.validation.mandatory"
|
||||
|
||||
@@ -50,7 +50,19 @@ namespace Umbraco.Web.Editors.Binders
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: anything after 3 parts we can put in metadata
|
||||
//if there are 4 parts part 4 is always segment
|
||||
string segment = null;
|
||||
if (parts.Length > 3)
|
||||
{
|
||||
segment = parts[3];
|
||||
//normalize to null if empty
|
||||
if (segment.IsNullOrWhiteSpace())
|
||||
{
|
||||
segment = null;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: anything after 4 parts we can put in metadata
|
||||
|
||||
var fileName = file.Headers.ContentDisposition.FileName.Trim('\"');
|
||||
|
||||
@@ -59,6 +71,7 @@ namespace Umbraco.Web.Editors.Binders
|
||||
TempFilePath = file.LocalFileName,
|
||||
PropertyAlias = propAlias,
|
||||
Culture = culture,
|
||||
Segment = segment,
|
||||
FileName = fileName
|
||||
});
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace Umbraco.Web.Editors
|
||||
|
||||
// prepare files, if any matching property and culture
|
||||
var files = contentItem.UploadedFiles
|
||||
.Where(x => x.PropertyAlias == propertyDto.Alias && x.Culture == propertyDto.Culture)
|
||||
.Where(x => x.PropertyAlias == propertyDto.Alias && x.Culture == propertyDto.Culture && x.Segment == propertyDto.Segment)
|
||||
.ToArray();
|
||||
|
||||
foreach (var file in files)
|
||||
|
||||
Reference in New Issue
Block a user