This commit is contained in:
Mads Rasmussen
2018-05-20 12:16:50 +02:00
17 changed files with 77 additions and 446 deletions
@@ -1,28 +0,0 @@
angular.module("umbraco")
.controller("Umbraco.PropertyEditors.Grid.EmbedController",
function ($scope, $rootScope, $timeout) {
$scope.setEmbed = function(){
$scope.embedDialog = {};
$scope.embedDialog.view = "embed";
$scope.embedDialog.show = true;
$scope.embedDialog.submit = function(model) {
$scope.control.value = model.embed.preview;
$scope.embedDialog.show = false;
$scope.embedDialog = null;
};
$scope.embedDialog.close = function(oldModel) {
$scope.embedDialog.show = false;
$scope.embedDialog = null;
};
};
$timeout(function(){
if($scope.control.$initializing){
$scope.setEmbed();
}
}, 200);
});
@@ -1,17 +0,0 @@
<div ng-controller="Umbraco.PropertyEditors.Grid.EmbedController">
<div class="umb-editor-placeholder" ng-click="setEmbed()" ng-if="control.value === null">
<i class="icon icon-movie-alt"></i>
<div class="help-text"><localize key="grid_clickToEmbed">Click to embed</localize></div>
</div>
<div ng-if="control.value" ng-bind-html-unsafe="control.value"></div>
<umb-overlay
ng-if="embedDialog.show"
model="embedDialog"
view="embedDialog.view"
position="right">
</umb-overlay>
</div>
@@ -1,2 +0,0 @@
<p class="red">Something went wrong with this editor, below is the data stored:</p>
<pre>{{control | json}}</pre>
@@ -1,64 +0,0 @@
angular.module("umbraco")
.controller("Umbraco.PropertyEditors.Grid.MacroController",
function ($scope, $rootScope, $timeout, dialogService, macroResource, macroService, $routeParams) {
$scope.title = "Click to insert macro";
$scope.setMacro = function(){
var dialogData = {
richTextEditor: true,
macroData: $scope.control.value || {
macroAlias: $scope.control.editor.config && $scope.control.editor.config.macroAlias
? $scope.control.editor.config.macroAlias : ""
}
};
$scope.macroPickerOverlay = {};
$scope.macroPickerOverlay.view = "macropicker";
$scope.macroPickerOverlay.dialogData = dialogData;
$scope.macroPickerOverlay.show = true;
$scope.macroPickerOverlay.submit = function(model) {
var macroObject = macroService.collectValueData(model.selectedMacro, model.macroParams, dialogData.renderingEngine);
$scope.control.value = {
macroAlias: macroObject.macroAlias,
macroParamsDictionary: macroObject.macroParamsDictionary
};
$scope.setPreview($scope.control.value );
$scope.macroPickerOverlay.show = false;
$scope.macroPickerOverlay = null;
};
$scope.macroPickerOverlay.close = function(oldModel) {
$scope.macroPickerOverlay.show = false;
$scope.macroPickerOverlay = null;
};
};
$scope.setPreview = function(macro){
var contentId = $routeParams.id;
macroResource.getMacroResultAsHtmlForEditor(macro.macroAlias, contentId, macro.macroParamsDictionary)
.then(function (htmlResult) {
$scope.title = macro.macroAlias;
if(htmlResult.trim().length > 0 && htmlResult.indexOf("Macro:") < 0){
$scope.preview = htmlResult;
}
});
};
$timeout(function(){
if($scope.control.$initializing){
$scope.setMacro();
}else if($scope.control.value){
$scope.setPreview($scope.control.value);
}
}, 200);
});
@@ -1,23 +0,0 @@
<div ng-controller="Umbraco.PropertyEditors.Grid.MacroController">
<div class="umb-editor-placeholder" ng-click="setMacro()">
<div ng-if="!preview">
<i class="icon icon-settings-alt"></i>
<div class="help-text">{{title}}</div>
</div>
<div ng-if="preview">
<div
ng-if="preview" style="text-align: left; pointer-events: none; cursor: default;"
ng-bind-html-unsafe="preview">
</div>
</div>
</div>
<umb-overlay
ng-if="macroPickerOverlay.show"
model="macroPickerOverlay"
view="macroPickerOverlay.view"
position="right">
</umb-overlay>
</div>
@@ -1,78 +0,0 @@
angular.module("umbraco")
.controller("Umbraco.PropertyEditors.Grid.MediaController",
function ($scope, $rootScope, $timeout, userService) {
if (!$scope.model.config.startNodeId) {
userService.getCurrentUser().then(function (userData) {
$scope.model.config.startNodeId = userData.startMediaIds.length !== 1 ? -1 : userData.startMediaIds[0];
$scope.model.config.startNodeIsVirtual = userData.startMediaIds.length !== 1;
});
}
$scope.setImage = function(){
$scope.mediaPickerOverlay = {};
$scope.mediaPickerOverlay.view = "mediapicker";
$scope.mediaPickerOverlay.startNodeId = $scope.model.config && $scope.model.config.startNodeId ? $scope.model.config.startNodeId : undefined;
$scope.mediaPickerOverlay.startNodeIsVirtual = $scope.mediaPickerOverlay.startNodeId ? $scope.model.config.startNodeIsVirtual : undefined;
$scope.mediaPickerOverlay.cropSize = $scope.control.editor.config && $scope.control.editor.config.size ? $scope.control.editor.config.size : undefined;
$scope.mediaPickerOverlay.showDetails = true;
$scope.mediaPickerOverlay.disableFolderSelect = true;
$scope.mediaPickerOverlay.onlyImages = true;
$scope.mediaPickerOverlay.show = true;
$scope.mediaPickerOverlay.submit = function(model) {
var selectedImage = model.selectedImages[0];
$scope.control.value = {
focalPoint: selectedImage.focalPoint,
id: selectedImage.id,
udi: selectedImage.udi,
image: selectedImage.image,
altText: selectedImage.altText
};
$scope.setUrl();
$scope.mediaPickerOverlay.show = false;
$scope.mediaPickerOverlay = null;
};
$scope.mediaPickerOverlay.close = function(oldModel) {
$scope.mediaPickerOverlay.show = false;
$scope.mediaPickerOverlay = null;
};
};
$scope.setUrl = function(){
if($scope.control.value.image){
var url = $scope.control.value.image;
if($scope.control.editor.config && $scope.control.editor.config.size){
url += "?width=" + $scope.control.editor.config.size.width;
url += "&height=" + $scope.control.editor.config.size.height;
url += "&animationprocessmode=first";
if($scope.control.value.focalPoint){
url += "&center=" + $scope.control.value.focalPoint.top +"," + $scope.control.value.focalPoint.left;
url += "&mode=crop";
}
}
// set default size if no crop present (moved from the view)
if (url.indexOf('?') == -1)
{
url += "?width=800&upscale=false&animationprocessmode=false"
}
$scope.url = url;
}
};
$timeout(function(){
if($scope.control.$initializing){
$scope.setImage();
}else if($scope.control.value){
$scope.setUrl();
}
}, 200);
});
@@ -1,24 +0,0 @@
<div ng-controller="Umbraco.PropertyEditors.Grid.MediaController">
<div class="umb-editor-placeholder" ng-click="setImage()" ng-if="control.value === null">
<i class="icon icon-picture"></i>
<div ng-id="!control.$inserted" class="help-text"><localize key="grid_clickToInsertImage">Click to insert image</localize></div>
</div>
<div ng-if="control.value">
<img
ng-if="url"
ng-click="setImage()"
ng-src="{{url}}"
class="fullSizeImage" />
<input type="text" class="caption" ng-model="control.value.caption" localize="placeholder" placeholder="@grid_placeholderImageCaption" />
</div>
<umb-overlay
ng-if="mediaPickerOverlay.show"
model="mediaPickerOverlay"
view="mediaPickerOverlay.view"
position="right">
</umb-overlay>
</div>
@@ -1,74 +0,0 @@
(function() {
"use strict";
function GridRichTextEditorController($scope, tinyMceService, macroService) {
var vm = this;
vm.openLinkPicker = openLinkPicker;
vm.openMediaPicker = openMediaPicker;
vm.openMacroPicker = openMacroPicker;
vm.openEmbed = openEmbed;
function openLinkPicker(editor, currentTarget, anchorElement) {
vm.linkPickerOverlay = {
view: "linkpicker",
currentTarget: currentTarget,
show: true,
submit: function(model) {
tinyMceService.insertLinkInEditor(editor, model.target, anchorElement);
vm.linkPickerOverlay.show = false;
vm.linkPickerOverlay = null;
}
};
}
function openMediaPicker(editor, currentTarget, userData) {
vm.mediaPickerOverlay = {
currentTarget: currentTarget,
onlyImages: true,
showDetails: true,
startNodeId: userData.startMediaIds.length !== 1 ? -1 : userData.startMediaIds[0],
view: "mediapicker",
show: true,
submit: function(model) {
tinyMceService.insertMediaInEditor(editor, model.selectedImages[0]);
vm.mediaPickerOverlay.show = false;
vm.mediaPickerOverlay = null;
}
};
}
function openEmbed(editor) {
vm.embedOverlay = {
view: "embed",
show: true,
submit: function(model) {
tinyMceService.insertEmbeddedMediaInEditor(editor, model.embed.preview);
vm.embedOverlay.show = false;
vm.embedOverlay = null;
}
};
}
function openMacroPicker(editor, dialogData) {
vm.macroPickerOverlay = {
view: "macropicker",
dialogData: dialogData,
show: true,
submit: function(model) {
var macroObject = macroService.collectValueData(model.selectedMacro, model.macroParams, dialogData.renderingEngine);
tinyMceService.insertMacroInEditor(editor, macroObject, $scope);
vm.macroPickerOverlay.show = false;
vm.macroPickerOverlay = null;
}
};
}
}
angular.module("umbraco").controller("Umbraco.PropertyEditors.Grid.RichTextEditorController", GridRichTextEditorController);
})();
@@ -1,42 +0,0 @@
<div ng-controller="Umbraco.PropertyEditors.Grid.RichTextEditorController as vm">
<div
grid-rte
configuration="model.config.rte"
value="control.value"
unique-id="control.$uniqueId"
on-link-picker-click="vm.openLinkPicker"
on-media-picker-click="vm.openMediaPicker"
on-embed-click="vm.openEmbed"
on-macro-picker-click="vm.openMacroPicker">
</div>
<umb-overlay
ng-if="vm.linkPickerOverlay.show"
model="vm.linkPickerOverlay"
position="right"
view="vm.linkPickerOverlay.view">
</umb-overlay>
<umb-overlay
ng-if="vm.mediaPickerOverlay.show"
model="vm.mediaPickerOverlay"
position="right"
view="vm.mediaPickerOverlay.view">
</umb-overlay>
<umb-overlay
ng-if="vm.embedOverlay.show"
model="vm.embedOverlay"
position="right"
view="vm.embedOverlay.view">
</umb-overlay>
<umb-overlay
ng-if="vm.macroPickerOverlay.show"
model="vm.macroPickerOverlay"
view="vm.macroPickerOverlay.view"
position="right">
</umb-overlay>
</div>
@@ -1,8 +0,0 @@
angular.module("umbraco")
.controller("Umbraco.PropertyEditors.Grid.TextStringController",
function ($scope, $rootScope, $timeout, dialogService) {
});
@@ -1,9 +0,0 @@
<div>
<textarea
rows="1"
umb-auto-resize
umb-auto-focus
class="textstring input-block-level" id="{{control.uniqueId}}_text"
ng-model="control.value"
ng-attr-style="{{control.editor.config.style}}" localize="placeholder" placeholder="@grid_placeholderWriteHere"></textarea>
</div>
@@ -14,7 +14,7 @@ namespace Umbraco.Web.PropertyEditors
/// Due to maintaining backwards compatibility this data type stores the value as a string which is a comma separated value of the
/// ids of the individual items so we have logic in here to deal with that.
/// </remarks>
[DataEditor(Constants.PropertyEditors.Aliases.DropDownListMultiple, "Dropdown list multiple", "dropdown", Group = "lists", Icon="icon-bulleted-list", IsDeprecated = true)]
[DataEditor(Constants.PropertyEditors.Aliases.DropDownListMultiple, "(Obsolete) Dropdown list multiple", "dropdown", Group = "lists", Icon="icon-bulleted-list", IsDeprecated = true)]
public class DropDownMultiplePropertyEditor : DropDownMultipleWithKeysPropertyEditor
{
/// <summary>
@@ -14,7 +14,7 @@ namespace Umbraco.Web.PropertyEditors
/// Due to backwards compatibility, this editor stores the value as a CSV string listing
/// the ids of individual items.
/// </remarks>
[DataEditor(Constants.PropertyEditors.Aliases.DropdownlistMultiplePublishKeys, "Dropdown list multiple, publish keys", "dropdown", Group = "lists", Icon = "icon-bulleted-list", IsDeprecated = true)]
[DataEditor(Constants.PropertyEditors.Aliases.DropdownlistMultiplePublishKeys, "(Obsolete) Dropdown list multiple, publish keys", "dropdown", Group = "lists", Icon = "icon-bulleted-list", IsDeprecated = true)]
public class DropDownMultipleWithKeysPropertyEditor : DropDownPropertyEditor
{
private readonly ILocalizedTextService _textService;
@@ -18,7 +18,7 @@ namespace Umbraco.Web.PropertyEditors
/// as INT and we have logic in here to ensure it is formatted correctly including ensuring that the string value is published
/// in cache and not the int ID.
/// </remarks>
[DataEditor(Constants.PropertyEditors.Aliases.DropDownList, "Dropdown list", "dropdown", ValueType = ValueTypes.String, Group = "lists", Icon = "icon-indent", IsDeprecated = true)]
[DataEditor(Constants.PropertyEditors.Aliases.DropDownList, "(Obsolete) Dropdown list", "dropdown", ValueType = ValueTypes.String, Group = "lists", Icon = "icon-indent", IsDeprecated = true)]
public class DropDownPropertyEditor : DropDownWithKeysPropertyEditor
{
/// <summary>
@@ -13,7 +13,7 @@ namespace Umbraco.Web.PropertyEditors
/// as INT and we have logic in here to ensure it is formatted correctly including ensuring that the INT ID value is published
/// in cache and not the string value.
/// </remarks>
[DataEditor(Constants.PropertyEditors.Aliases.DropdownlistPublishKeys, "Dropdown list, publishing keys", "dropdown", ValueType = ValueTypes.Integer, Group = "lists", Icon = "icon-indent", IsDeprecated = true)]
[DataEditor(Constants.PropertyEditors.Aliases.DropdownlistPublishKeys, "(Obsolete) Dropdown list, publishing keys", "dropdown", ValueType = ValueTypes.Integer, Group = "lists", Icon = "icon-indent", IsDeprecated = true)]
public class DropDownWithKeysPropertyEditor : DataEditor
{
private readonly ILocalizedTextService _textService;
@@ -18,91 +18,91 @@ namespace Umbraco.Web.PropertyEditors
/// <summary>
/// Represents a grid property and parameter editor.
/// </summary>
[DataEditor(Constants.PropertyEditors.Aliases.Grid2, "Grid", "grid", HideLabel = true, ValueType = ValueTypes.Json, Group="rich content", Icon="icon-layout")]
[DataEditor(Constants.PropertyEditors.Aliases.Grid2, "Grid", "grid2", HideLabel = true, ValueType = ValueTypes.Json, Group="rich content", Icon="icon-layout")]
public class Grid2PropertyEditor : DataEditor
{
public Grid2PropertyEditor(ILogger logger)
: base(logger)
{ }
internal void DocumentWriting(object sender, Examine.LuceneEngine.DocumentWritingEventArgs e)
{
foreach (var value in e.ValueSet.Values)
{
//if there is a value, it's a string and it's detected as json
if (value.Value.Count > 0 && value.Value[0] != null && (value.Value[0] is string firstVal) && firstVal.DetectIsJson())
{
try
{
//TODO: We should deserialize this to Umbraco.Core.Models.GridValue instead of doing the below
var json = JsonConvert.DeserializeObject<JObject>(firstVal);
//internal void DocumentWriting(object sender, Examine.LuceneEngine.DocumentWritingEventArgs e)
//{
// foreach (var value in e.ValueSet.Values)
// {
// //if there is a value, it's a string and it's detected as json
// if (value.Value.Count > 0 && value.Value[0] != null && (value.Value[0] is string firstVal) && firstVal.DetectIsJson())
// {
// try
// {
// //TODO: We should deserialize this to Umbraco.Core.Models.GridValue instead of doing the below
// var json = JsonConvert.DeserializeObject<JObject>(firstVal);
//check if this is formatted for grid json
if (json.HasValues && json.TryGetValue("name", out _) && json.TryGetValue("sections", out _))
{
//get all values and put them into a single field (using JsonPath)
var sb = new StringBuilder();
foreach (var row in json.SelectTokens("$.sections[*].rows[*]"))
{
var rowName = row["name"].Value<string>();
var areaVals = row.SelectTokens("$.areas[*].controls[*].value");
// //check if this is formatted for grid json
// if (json.HasValues && json.TryGetValue("name", out _) && json.TryGetValue("sections", out _))
// {
// //get all values and put them into a single field (using JsonPath)
// var sb = new StringBuilder();
// foreach (var row in json.SelectTokens("$.sections[*].rows[*]"))
// {
// var rowName = row["name"].Value<string>();
// var areaVals = row.SelectTokens("$.areas[*].controls[*].value");
foreach (var areaVal in areaVals)
{
//TODO: If it's not a string, then it's a json formatted value -
// we cannot really index this in a smart way since it could be 'anything'
if (areaVal.Type == JTokenType.String)
{
var str = areaVal.Value<string>();
str = XmlHelper.CouldItBeXml(str) ? str.StripHtml() : str;
sb.Append(str);
sb.Append(" ");
// foreach (var areaVal in areaVals)
// {
// //TODO: If it's not a string, then it's a json formatted value -
// // we cannot really index this in a smart way since it could be 'anything'
// if (areaVal.Type == JTokenType.String)
// {
// var str = areaVal.Value<string>();
// str = XmlHelper.CouldItBeXml(str) ? str.StripHtml() : str;
// sb.Append(str);
// sb.Append(" ");
//add the row name as an individual field
e.Document.Add(
new Field(
$"{value.Key}.{rowName}", str, Field.Store.YES, Field.Index.ANALYZED));
}
// //add the row name as an individual field
// e.Document.Add(
// new Field(
// $"{value.Key}.{rowName}", str, Field.Store.YES, Field.Index.ANALYZED));
// }
}
}
// }
// }
if (sb.Length > 0)
{
//First save the raw value to a raw field
e.Document.Add(
new Field(
$"{UmbracoExamineIndexer.RawFieldPrefix}{value.Key}",
firstVal, Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS, Field.TermVector.NO));
// if (sb.Length > 0)
// {
// //First save the raw value to a raw field
// e.Document.Add(
// new Field(
// $"{UmbracoExamineIndexer.RawFieldPrefix}{value.Key}",
// firstVal, Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS, Field.TermVector.NO));
//now replace the original value with the combined/cleaned value
e.Document.RemoveField(value.Key);
e.Document.Add(
new Field(
value.Key,
sb.ToString(), Field.Store.YES, Field.Index.ANALYZED));
}
}
}
catch (InvalidCastException)
{
//swallow...on purpose, there's a chance that this isn't the json format we are looking for
// and we don't want that to affect the website.
}
catch (JsonException)
{
//swallow...on purpose, there's a chance that this isn't json and we don't want that to affect
// the website.
}
catch (ArgumentException)
{
//swallow on purpose to prevent this error:
// Can not add Newtonsoft.Json.Linq.JValue to Newtonsoft.Json.Linq.JObject.
}
}
// //now replace the original value with the combined/cleaned value
// e.Document.RemoveField(value.Key);
// e.Document.Add(
// new Field(
// value.Key,
// sb.ToString(), Field.Store.YES, Field.Index.ANALYZED));
// }
// }
// }
// catch (InvalidCastException)
// {
// //swallow...on purpose, there's a chance that this isn't the json format we are looking for
// // and we don't want that to affect the website.
// }
// catch (JsonException)
// {
// //swallow...on purpose, there's a chance that this isn't json and we don't want that to affect
// // the website.
// }
// catch (ArgumentException)
// {
// //swallow on purpose to prevent this error:
// // Can not add Newtonsoft.Json.Linq.JValue to Newtonsoft.Json.Linq.JObject.
// }
// }
}
}
// }
//}
/// <summary>
/// Overridden to ensure that the value is validated
@@ -18,7 +18,7 @@ namespace Umbraco.Web.PropertyEditors
/// <summary>
/// Represents a grid property and parameter editor.
/// </summary>
[DataEditor(Constants.PropertyEditors.Aliases.Grid, "Grid layout", "grid", HideLabel = true, ValueType = ValueTypes.Json, Group="rich content", Icon="icon-layout")]
[DataEditor(Constants.PropertyEditors.Aliases.Grid, "(Obsolete) Grid layout", "grid", HideLabel = true, ValueType = ValueTypes.Json, Group="rich content", Icon="icon-layout", IsDeprecated = true)]
public class GridPropertyEditor : DataEditor
{
public GridPropertyEditor(ILogger logger)