refresh of element view works on update, but it refreshes all elements

This commit is contained in:
2019-08-30 21:54:47 +02:00
parent 08664003e0
commit 56da96e46f
4 changed files with 92 additions and 46 deletions
@@ -11,6 +11,7 @@ angular.module('umbraco.directives').directive('unContent', function ($compile)
},
link: function (scope, element)
{
// get template
var template = scope.config && scope.config.nameTemplate ? scope.config.nameTemplate : null;
@@ -33,10 +34,22 @@ angular.module('umbraco.directives').directive('unContent', function ($compile)
$compile(element.contents())(scope);
}
//scope.$watch('item', function (value)
//var unsubscribe = scope.$on("ncSyncVal", function (ev, args)
//{
// if (args.key === scope.node.key)
// {
// render();
// }
//});
var unsubscribe = scope.$watch('item', function (value)
{
render();
});
scope.$on('$destroy', function ()
{
unsubscribe();
});
// first-time rendering
render();
@@ -366,6 +379,8 @@ angular.module("umbraco.directives").directive('uNestingContentEditor', [
function ()
{
var link = function ($scope)
{
var createModel = function ()
{
// Clone the model because some property editors
// do weird things like updating and config values
@@ -375,7 +390,7 @@ angular.module("umbraco.directives").directive('uNestingContentEditor', [
$scope.nodeContext = $scope.model;
// Find the selected tab
var selectedTab = $scope.model.variants[0].tabs[0];
$scope.selectedTab = $scope.model.variants[0].tabs[0];
if ($scope.tabAlias)
{
@@ -383,7 +398,7 @@ angular.module("umbraco.directives").directive('uNestingContentEditor', [
{
if (tab.alias.toLowerCase() === $scope.tabAlias.toLowerCase())
{
selectedTab = tab;
$scope.selectedTab = tab;
return;
}
});
@@ -410,10 +425,22 @@ angular.module("umbraco.directives").directive('uNestingContentEditor', [
//$scope.settingsProperties = settingsTab ? settingsTab.properties : [];
$scope.settingsProperties = [];
};
// Listen for incoming changes
var unsubscribeIn = $scope.$on("ncSyncInVal", function (ev, args)
{
if (args.key === $scope.model.key)
{
createModel();
}
});
// Listen for sync request
var unsubscribe = $scope.$on("ncSyncVal", function (ev, args)
{
unsubscribeIn();
if (args.key === $scope.model.key)
{
// Tell inner controls we are submitting
@@ -422,10 +449,10 @@ angular.module("umbraco.directives").directive('uNestingContentEditor', [
// Sync the values back
angular.forEach($scope.ngModel.variants[0].tabs, function (tab)
{
if (tab.alias.toLowerCase() === selectedTab.alias.toLowerCase())
if (tab.alias.toLowerCase() === $scope.selectedTab.alias.toLowerCase())
{
var localPropsMap = selectedTab.properties.reduce(function (map, obj)
var localPropsMap = $scope.selectedTab.properties.reduce(function (map, obj)
{
map[obj.alias] = obj;
return map;
@@ -448,6 +475,8 @@ angular.module("umbraco.directives").directive('uNestingContentEditor', [
{
unsubscribe();
});
createModel();
};
return {
@@ -16,7 +16,7 @@
<div class="unesting-item" ng-repeat="node in nodes"
unesting-alias="{{node.documentType.alias}}"
ng-class="{ 'is-active' : $parent.realCurrentNode.key === node.key, 'umb-nested-content__item--single' : $parent.singleMode, 'is-hidden': isHidden(model.value[$index]) }">
ng-class="{ 'is-active' : $parent.realCurrentNode.key === node.key, 'umb-nested-content__item--single' : $parent.singleMode, 'is-hidden': isHidden(model.value[$index], node) }">
<div class="unesting-item-header" ng-click="$parent.editNode($index)" ng-hide="$parent.singleMode">
@@ -637,9 +637,6 @@ angular.module("umbraco").controller("brothers.uNesting.PropertyEditorController
unsubscribe();
});
$scope.clickHide = function ($event, node, alias)
{
$event.preventDefault();
@@ -653,15 +650,30 @@ angular.module("umbraco").controller("brothers.uNesting.PropertyEditorController
var property = _.find(tab.properties, function (prop)
{
return tab.id !== 0 && prop.propertyAlias.toLowerCase() === 'unestinghide';
return prop.propertyAlias.toLowerCase() === 'unestinghide';
});
if (property)
{
property.value = property.value === '1' ? '0' : '1';
$scope.setDirty();
if ($scope.inited)
{
var newValues = [];
for (var i = 0; i < $scope.nodes.length; i++)
{
newValues.push(convertNodeIntoNCEntry($scope.nodes[i]));
}
$scope.model.value = newValues;
}
}
updateModel();
//if ($scope.realCurrentNode)
//{
// $scope.$broadcast("ncSyncInVal", { key: $scope.realCurrentNode.key });
//}
};
$scope.canHide = function (item)
@@ -669,7 +681,7 @@ angular.module("umbraco").controller("brothers.uNesting.PropertyEditorController
return typeof item['uNestingHide'] !== 'undefined';
};
$scope.isHidden = function (item)
$scope.isHidden = function (item, node)
{
return item['uNestingHide'] === '1';
};
+5
View File
@@ -42,6 +42,11 @@ namespace UmbracoPackages
/// <returns></returns>
public Dictionary<Udi, string> GetMediaByUdis([FromUri]Udi[] ids)
{
if (ids == null || ids.Length == 0 || (ids.Length == 1 && ids[0] == default(Udi)))
{
return new Dictionary<Udi, string>();
}
var foundMedia = Services.MediaService.GetByIds(ids.Select(x => (x as GuidUdi).Guid));
return foundMedia.ToDictionary(media => (Udi)media.GetUdi(), media =>
{