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) link: function (scope, element)
{ {
// get template // get template
var template = scope.config && scope.config.nameTemplate ? scope.config.nameTemplate : null; 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); $compile(element.contents())(scope);
} }
//scope.$watch('item', function (value) //var unsubscribe = scope.$on("ncSyncVal", function (ev, args)
//{ //{
// render(); // if (args.key === scope.node.key)
// {
// render();
// }
//}); //});
var unsubscribe = scope.$watch('item', function (value)
{
render();
});
scope.$on('$destroy', function ()
{
unsubscribe();
});
// first-time rendering // first-time rendering
render(); render();
@@ -367,53 +380,67 @@ angular.module("umbraco.directives").directive('uNestingContentEditor', [
{ {
var link = function ($scope) var link = function ($scope)
{ {
// Clone the model because some property editors var createModel = function ()
// do weird things like updating and config values
// so we want to ensure we start from a fresh every
// time, we'll just sync the value back when we need to
$scope.model = angular.copy($scope.ngModel);
$scope.nodeContext = $scope.model;
// Find the selected tab
var selectedTab = $scope.model.variants[0].tabs[0];
if ($scope.tabAlias)
{ {
angular.forEach($scope.model.variants[0].tabs, function (tab) // Clone the model because some property editors
// do weird things like updating and config values
// so we want to ensure we start from a fresh every
// time, we'll just sync the value back when we need to
$scope.model = angular.copy($scope.ngModel);
$scope.nodeContext = $scope.model;
// Find the selected tab
$scope.selectedTab = $scope.model.variants[0].tabs[0];
if ($scope.tabAlias)
{ {
if (tab.alias.toLowerCase() === $scope.tabAlias.toLowerCase()) angular.forEach($scope.model.variants[0].tabs, function (tab)
{ {
selectedTab = tab; if (tab.alias.toLowerCase() === $scope.tabAlias.toLowerCase())
return; {
} $scope.selectedTab = tab;
return;
}
});
}
$scope.tabs = $scope.model.variants[0].tabs;
var contentTab = _.find($scope.tabs, function (tab)
{
var alias = tab.alias.toLowerCase();
return tab.id !== 0 && alias !== 'unestingsettings' && (!$scope.tabAlias || alias === $scope.tabAlias.toLowerCase());
}); });
}
$scope.tabs = $scope.model.variants[0].tabs; $scope.contentProperties = _.filter(contentTab.properties, function (prop)
{
return prop.propertyAlias.toLowerCase() !== 'unestinghide';
});
var contentTab = _.find($scope.tabs, function (tab) //var settingsTab = _.find($scope.tabs, function (tab)
//{
// var alias = tab.alias.toLowerCase();
// return tab.id !== 0 && alias === 'unestingsettings';
//});
//$scope.settingsProperties = settingsTab ? settingsTab.properties : [];
$scope.settingsProperties = [];
};
// Listen for incoming changes
var unsubscribeIn = $scope.$on("ncSyncInVal", function (ev, args)
{ {
var alias = tab.alias.toLowerCase(); if (args.key === $scope.model.key)
return tab.id !== 0 && alias !== 'unestingsettings' && (!$scope.tabAlias || alias === $scope.tabAlias.toLowerCase()); {
createModel();
}
}); });
$scope.contentProperties = _.filter(contentTab.properties, function (prop)
{
return prop.propertyAlias.toLowerCase() !== 'unestinghide';
});
//var settingsTab = _.find($scope.tabs, function (tab)
//{
// var alias = tab.alias.toLowerCase();
// return tab.id !== 0 && alias === 'unestingsettings';
//});
//$scope.settingsProperties = settingsTab ? settingsTab.properties : [];
$scope.settingsProperties = [];
// Listen for sync request // Listen for sync request
var unsubscribe = $scope.$on("ncSyncVal", function (ev, args) var unsubscribe = $scope.$on("ncSyncVal", function (ev, args)
{ {
unsubscribeIn();
if (args.key === $scope.model.key) if (args.key === $scope.model.key)
{ {
// Tell inner controls we are submitting // Tell inner controls we are submitting
@@ -422,10 +449,10 @@ angular.module("umbraco.directives").directive('uNestingContentEditor', [
// Sync the values back // Sync the values back
angular.forEach($scope.ngModel.variants[0].tabs, function (tab) 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; map[obj.alias] = obj;
return map; return map;
@@ -448,6 +475,8 @@ angular.module("umbraco.directives").directive('uNestingContentEditor', [
{ {
unsubscribe(); unsubscribe();
}); });
createModel();
}; };
return { return {
@@ -16,7 +16,7 @@
<div class="unesting-item" ng-repeat="node in nodes" <div class="unesting-item" ng-repeat="node in nodes"
unesting-alias="{{node.documentType.alias}}" 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"> <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(); unsubscribe();
}); });
$scope.clickHide = function ($event, node, alias) $scope.clickHide = function ($event, node, alias)
{ {
$event.preventDefault(); $event.preventDefault();
@@ -653,15 +650,30 @@ angular.module("umbraco").controller("brothers.uNesting.PropertyEditorController
var property = _.find(tab.properties, function (prop) var property = _.find(tab.properties, function (prop)
{ {
return tab.id !== 0 && prop.propertyAlias.toLowerCase() === 'unestinghide'; return prop.propertyAlias.toLowerCase() === 'unestinghide';
}); });
if (property) if (property)
{ {
property.value = property.value === '1' ? '0' : '1'; 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) $scope.canHide = function (item)
@@ -669,7 +681,7 @@ angular.module("umbraco").controller("brothers.uNesting.PropertyEditorController
return typeof item['uNestingHide'] !== 'undefined'; return typeof item['uNestingHide'] !== 'undefined';
}; };
$scope.isHidden = function (item) $scope.isHidden = function (item, node)
{ {
return item['uNestingHide'] === '1'; return item['uNestingHide'] === '1';
}; };
+5
View File
@@ -42,6 +42,11 @@ namespace UmbracoPackages
/// <returns></returns> /// <returns></returns>
public Dictionary<Udi, string> GetMediaByUdis([FromUri]Udi[] ids) 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)); var foundMedia = Services.MediaService.GetByIds(ids.Select(x => (x as GuidUdi).Guid));
return foundMedia.ToDictionary(media => (Udi)media.GetUdi(), media => return foundMedia.ToDictionary(media => (Udi)media.GetUdi(), media =>
{ {