working prototype

This commit is contained in:
Niels Lyngsø
2019-04-26 15:15:27 +02:00
parent 4d3154c7fa
commit 48ceb0d41d
3 changed files with 43 additions and 60 deletions

View File

@@ -3,7 +3,7 @@
function () {
var link = function ($scope) {
// 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
@@ -31,8 +31,6 @@
// Tell inner controls we are submitting
$scope.$broadcast("formSubmitting", { scope: $scope });
console.log("Form Submitting:: ", $scope.ngModel);
// Sync the values back
angular.forEach($scope.ngModel.variants[0].tabs, function (tab) {

View File

@@ -64,52 +64,38 @@ function copyService(notificationsService, eventsService) {
storage = new Object();
}
if(nodeType === "content" || nodeType === "element") {
if(data.contentTypeAlias === undefined) {
// missing contentTypeAlias... then we cant copy jet.
success = false;
}
}
/**
Will need to store things differently...
Can we copy real IpublishedContent...
And should I wrap data into a entry-object knowing about the data type..
*/
delete data.key;
delete data.$$hashKey;
if(storage.items === undefined) {
storage.items = [];
}
storage.items.push({nodeType:nodeType, data:data});
var shallowCloneData = Object.assign({}, data);// Notice only a shallow copy, since we dont need to deep copy. (that will happen when storing the data)
delete shallowCloneData.key;
delete shallowCloneData.$$hashKey;
var entry = {nodeType:nodeType, data:shallowCloneData};
storage.items.push(entry);
if (saveStorage(storage) === true) {
notificationsService.success("", "Copied to clipboard.");
notificationsService.success("Clipboard", "Copied to clipboard.");
} else {
notificationsService.success("", "Couldnt copy this data to clipboard.");
notificationsService.success("Clipboard", "Couldnt copy this data to clipboard.");
}
};
service.supportsCopy = supportsLocalStorage;
service.hasDataOfType = function(nodeType, nodeTypeAliases) {
service.hasEntriesOfType = function(nodeType, nodeTypeAliases) {
if(service.retriveDataOfType(nodeType, nodeTypeAliases).length > 0) {
if(service.retriveEntriesOfType(nodeType, nodeTypeAliases).length > 0) {
return true;
}
return false;
};
service.retriveDataOfType = function(nodeType, nodeTypeAliases) {
service.retriveEntriesOfType = function(nodeType, nodeTypeAliases) {
var storage = retriveStorage();
@@ -117,19 +103,22 @@ function copyService(notificationsService, eventsService) {
return [];
}
var itemsOfType = storage.items.filter(
var filteretEntries = storage.items.filter(
(item) => item.nodeType === nodeType
);
if (nodeTypeAliases) {
return itemsOfType.filter(
filteretEntries = filteretEntries.filter(
(item) => {
return nodeTypeAliases.filter(alias => alias === item.data.contentTypeAlias).length > 0;
}
);
} else {
return itemsOfType;
}
return filteretEntries;
};
service.retriveDataOfType = function(nodeType, nodeTypeAliases) {
return service.retriveEntriesOfType(nodeType, nodeTypeAliases).map((x) => x.data);
};

View File

@@ -113,7 +113,7 @@ angular.module("umbraco").controller("Umbraco.PropertyEditors.NestedContent.Prop
$scope.addNode = function (alias) {
var scaffold = $scope.getScaffold(alias);
var newNode = initNode(scaffold, null);
var newNode = createNode(scaffold, null);
$scope.currentNode = newNode;
$scope.setDirty();
@@ -224,8 +224,7 @@ angular.module("umbraco").controller("Umbraco.PropertyEditors.NestedContent.Prop
if ($scope.nodes[idx].name !== name) {
$scope.nodes[idx].name = name;
}
return name;
};
@@ -281,6 +280,9 @@ angular.module("umbraco").controller("Umbraco.PropertyEditors.NestedContent.Prop
$scope.showPaste = false;
$scope.clickCopy = function($event, node) {
syncCurrentNode();
copyService.copy("elementType", node);
$event.stopPropagation();
}
@@ -293,16 +295,17 @@ angular.module("umbraco").controller("Umbraco.PropertyEditors.NestedContent.Prop
return;
}
console.log(newNode);
// generate a new key.
newNode.key = String.CreateGuid();
$scope.nodes.push(newNode);
updatemodel();
//updateModel();// done by setting current node...
$scope.currentNode = newNode;
}
function checkAbilityToPasteContent() {
$scope.showPaste = copyService.hasDataOfType("elementType", contentTypeAliases);
$scope.showPaste = copyService.hasEntriesOfType("elementType", contentTypeAliases);
}
eventsService.on("copyService.storageUpdate", checkAbilityToPasteContent);
@@ -373,7 +376,7 @@ angular.module("umbraco").controller("Umbraco.PropertyEditors.NestedContent.Prop
// No such scaffold - the content type might have been deleted. We need to skip it.
continue;
}
initNode(scaffold, item);
createNode(scaffold, item);
}
}
@@ -394,28 +397,21 @@ angular.module("umbraco").controller("Umbraco.PropertyEditors.NestedContent.Prop
checkAbilityToPasteContent();
}
}
var initNode = function (scaffold, item) {
function createNode(scaffold, fromNcEntry) {
var node = angular.copy(scaffold);
node.key = item && item.key ? item.key : String.CreateGuid();
//node.ncContentTypeAlias = scaffold.contentTypeAlias;
node.key = fromNcEntry && fromNcEntry.key ? fromNcEntry.key : String.CreateGuid();
for (var v = 0; v < node.variants.length; v++) {
var variant = node.variants[v];
console.log("- variant:", variant);
for (var t = 0; t < variant.tabs.length; t++) {
var tab = variant.tabs[t];
console.log("-- tab:", tab);
for (var p = 0; p < tab.properties.length; p++) {
var prop = tab.properties[p];
console.log("--- prop:", prop.alias, prop.value);
prop.propertyAlias = prop.alias;
prop.alias = $scope.model.alias + "___" + prop.alias;
// Force validation to occur server side as this is the
@@ -426,17 +422,13 @@ angular.module("umbraco").controller("Umbraco.PropertyEditors.NestedContent.Prop
pattern: ""
};
if (item && item[prop.propertyAlias]) {
console.log("setting property: ", prop.propertyAlias, item[prop.propertyAlias]);
prop.value = item[prop.propertyAlias];
if (fromNcEntry && fromNcEntry[prop.propertyAlias]) {
prop.value = fromNcEntry[prop.propertyAlias];
}
}
}
}
console.log("initNode node:", node);
$scope.nodes.push(node);
return node;
@@ -457,14 +449,18 @@ angular.module("umbraco").controller("Umbraco.PropertyEditors.NestedContent.Prop
}
}
}
console.log(obj);
return obj;
}
function updateModel() {
function syncCurrentNode() {
if ($scope.realCurrentNode) {
$scope.$broadcast("ncSyncVal", { key: $scope.realCurrentNode.key });
}
}
function updateModel() {
syncCurrentNode();
if (inited) {
var newValues = [];
for (var i = 0; i < $scope.nodes.length; i++) {