From a4fce32d55b3dd9ca6e67f0d32334840afe3ddc3 Mon Sep 17 00:00:00 2001 From: Mark Drake Date: Fri, 26 Jan 2018 10:01:19 -0500 Subject: [PATCH 01/29] copy and paste feature through local storage --- .../StackedContent/css/stackedcontent.css | 16 +++--- .../js/stackedcontent.controllers.js | 49 ++++++++++++++++++- .../StackedContent/views/stackedcontent.html | 9 ++-- 3 files changed, 63 insertions(+), 11 deletions(-) diff --git a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/css/stackedcontent.css b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/css/stackedcontent.css index 8e156fa..f57ec54 100644 --- a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/css/stackedcontent.css +++ b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/css/stackedcontent.css @@ -141,6 +141,7 @@ .stack__button, .stack__add-button, +.stack__paste-button, .stack__buttons .umb_confirm-action__overlay-action { display: inline-block; background-color: #2e8aea; @@ -156,6 +157,7 @@ .stack__button:hover, .stack__add-button:hover, +.stack__paste-button:hover, .stack__buttons .umb_confirm-action__overlay-action.-cancel:hover, .stack__buttons .umb_confirm-action__overlay-action.-confirm:hover { color: white !important; @@ -170,7 +172,8 @@ background-color: #e74c3c; } -.stack__add-button { +.stack__add-button, +.stack__paste-button { -webkit-border-radius: 2px; -moz-border-radius: 2px; border-radius: 2px; @@ -181,13 +184,11 @@ position: relative; height: 10px; z-index: 15; + text-align: center; } -.stack__add-bar .stack__add-button { - position: absolute; - left: 50%; - top: 50%; - margin: -15px 0 0 -15px; +.stack__add-bar .stack__add-button, +.stack__add-bar .stack__paste-button { opacity: 0; transition: opacity .0s ease-in-out; -moz-transition: opacity .0s ease-in-out; @@ -207,7 +208,8 @@ height: 20px; } -.stack__add-bar:hover .stack__add-button { +.stack__add-bar:hover .stack__add-button, +.stack__add-bar:hover .stack__paste-button { opacity: 1; transition-duration: .25s; -moz-transition-duration: .25s; diff --git a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js index 5e1d0cb..6707dc9 100644 --- a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js +++ b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js @@ -2,10 +2,11 @@ "$scope", "editorState", + "notificationsService", "innerContentService", "Our.Umbraco.StackedContent.Resources.StackedContentResources", - function ($scope, editorState, innerContentService, scResources) { + function ($scope, editorState, notificationsService, innerContentService, scResources) { $scope.inited = false; $scope.markup = {}; @@ -20,6 +21,12 @@ return $scope.model.config.singleItemMode !== "1"; } + $scope.canPaste = function () { + var stackedContentItem = JSON.parse(window.localStorage.getItem("StackedContentCopy")); + if (stackedContentItem && validateModel(stackedContentItem)) return true; + return false; + } + $scope.addContent = function (evt, idx) { $scope.overlayConfig.event = evt; $scope.overlayConfig.data = { model: null, idx: idx, action: "add" }; @@ -36,6 +43,36 @@ $scope.model.value.splice(idx, 1); } + $scope.copyToLocalStorage = function (evt, idx) { + var stackedContentItem = Object.assign({}, $scope.model.value[idx]); + stackedContentItem.key = ""; + stackedContentItem.$$hashKey = ""; + + if (validateModel(stackedContentItem)) { + window.localStorage.setItem("StackedContentCopy", JSON.stringify(stackedContentItem)); + notificationsService.success("Stacked Content", "Copied to clipboard."); + return; + } else { + notificationsService.error("Stacked Content", "Sorry, something went wrong."); + } + } + + $scope.pasteFromLocalStorage = function (evt, idx) { + var stackedContentItem = JSON.parse(window.localStorage.getItem("StackedContentCopy")); + if (!stackedContentItem) { + notificationsService.error("Stacked Content", "You need to copy content first."); + return; + } + if (validateModel(stackedContentItem)) { + $scope.overlayConfig.event = evt; + $scope.overlayConfig.data = { model: stackedContentItem, idx: idx, action: "add" }; + $scope.overlayConfig.show = true; + return; + } else { + notificationsService.error("Stacked Content", "Sorry, this content is not allowed here."); + } + } + $scope.sortableOptions = { axis: 'y', cursor: "move", @@ -68,6 +105,16 @@ return $scope.model.config.disablePreview !== "1"; } + var validateModel = function (model) { + try { + console.log($scope.model.config.contentTypes); + if (!model || !model.icContentTypeAlias) return false; + if (!$scope.model.config.contentTypes.filter(x => x.icContentTypeAlias === model.icContentTypeAlias).length) return false; + return true; + } catch (e) { + return false; + } + } // Set overlay config $scope.overlayConfig = { diff --git a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/views/stackedcontent.html b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/views/stackedcontent.html index 517e56b..467fffc 100644 --- a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/views/stackedcontent.html +++ b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/views/stackedcontent.html @@ -14,7 +14,8 @@
- + +
@@ -40,7 +42,8 @@

{{itm.name}}

- + +
From 3c185074436546ba1b00da285910b1ec3857baa8 Mon Sep 17 00:00:00 2001 From: Mark Drake Date: Fri, 26 Jan 2018 10:31:06 -0500 Subject: [PATCH 02/29] canCopy method added --- .../StackedContent/js/stackedcontent.controllers.js | 12 +++++++++++- .../StackedContent/views/stackedcontent.html | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js index 6707dc9..dcb21e0 100644 --- a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js +++ b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js @@ -21,6 +21,17 @@ return $scope.model.config.singleItemMode !== "1"; } + $scope.canCopy = function () { + var test = "test"; + try { + window.localStorage.setItem(test, test); + window.localStorage.removeItem(test); + return true; + } catch (e) { + return false; + } + } + $scope.canPaste = function () { var stackedContentItem = JSON.parse(window.localStorage.getItem("StackedContentCopy")); if (stackedContentItem && validateModel(stackedContentItem)) return true; @@ -107,7 +118,6 @@ var validateModel = function (model) { try { - console.log($scope.model.config.contentTypes); if (!model || !model.icContentTypeAlias) return false; if (!$scope.model.config.contentTypes.filter(x => x.icContentTypeAlias === model.icContentTypeAlias).length) return false; return true; diff --git a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/views/stackedcontent.html b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/views/stackedcontent.html index 467fffc..b8c9088 100644 --- a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/views/stackedcontent.html +++ b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/views/stackedcontent.html @@ -33,7 +33,7 @@

{{itm.name}}

on-cancel="prompts[itm.key] = false"> - + From 2cf73777382bd4849a84fcf63a64e99389fc663d Mon Sep 17 00:00:00 2001 From: Mark Drake Date: Mon, 29 Jan 2018 08:09:49 -0500 Subject: [PATCH 03/29] replaced assign with extend for greater support, moved copy before delete --- .../App_Plugins/StackedContent/js/stackedcontent.controllers.js | 2 +- .../Web/UI/App_Plugins/StackedContent/views/stackedcontent.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js index dcb21e0..6fe35f7 100644 --- a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js +++ b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js @@ -55,7 +55,7 @@ } $scope.copyToLocalStorage = function (evt, idx) { - var stackedContentItem = Object.assign({}, $scope.model.value[idx]); + var stackedContentItem = angular.extend({}, $scope.model.value[idx]); stackedContentItem.key = ""; stackedContentItem.$$hashKey = ""; diff --git a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/views/stackedcontent.html b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/views/stackedcontent.html index b8c9088..4354da7 100644 --- a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/views/stackedcontent.html +++ b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/views/stackedcontent.html @@ -27,13 +27,13 @@

{{itm.name}}

+ -
From a79a588bdc3d4ee2fe60840ed902f30de8c5b534 Mon Sep 17 00:00:00 2001 From: Mark Drake Date: Mon, 29 Jan 2018 08:57:50 -0500 Subject: [PATCH 04/29] replaced the paste icon with icon-paste-in --- .../UI/App_Plugins/StackedContent/views/stackedcontent.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/views/stackedcontent.html b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/views/stackedcontent.html index 4354da7..df87783 100644 --- a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/views/stackedcontent.html +++ b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/views/stackedcontent.html @@ -15,7 +15,7 @@
- +
@@ -27,7 +27,7 @@

{{itm.name}}

- + {{itm.name}}
- +
From 40af6771ddb9278a9d5755bccf964a1902e09b61 Mon Sep 17 00:00:00 2001 From: leekelleher Date: Thu, 19 Apr 2018 17:22:50 +0100 Subject: [PATCH 05/29] Used JSON parse/stringify to clone the object (to cover any deep structures) Removed the `$$hashKey` property - setting it as empty caused Angular issues. Auto-generated a new GUID when the item is pasted. --- .../StackedContent/js/stackedcontent.controllers.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js index 2a14971..866a974 100644 --- a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js +++ b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js @@ -56,9 +56,9 @@ } $scope.copyToLocalStorage = function (evt, idx) { - var stackedContentItem = angular.extend({}, $scope.model.value[idx]); + var stackedContentItem = JSON.parse(JSON.stringify($scope.model.value[idx])); stackedContentItem.key = ""; - stackedContentItem.$$hashKey = ""; + delete stackedContentItem.$$hashKey; if (validateModel(stackedContentItem)) { window.localStorage.setItem("StackedContentCopy", JSON.stringify(stackedContentItem)); @@ -71,6 +71,7 @@ $scope.pasteFromLocalStorage = function (evt, idx) { var stackedContentItem = JSON.parse(window.localStorage.getItem("StackedContentCopy")); + stackedContentItem.key = innerContentService.generateUid(); if (!stackedContentItem) { notificationsService.error("Stacked Content", "You need to copy content first."); return; From b14454d25915387151fe07c70546e4f37d70a63c Mon Sep 17 00:00:00 2001 From: leekelleher Date: Thu, 19 Apr 2018 17:23:15 +0100 Subject: [PATCH 06/29] Replaced the check for the Alias with the GUID --- .../StackedContent/js/stackedcontent.controllers.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js index 866a974..b1314cc 100644 --- a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js +++ b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js @@ -127,8 +127,8 @@ var validateModel = function (model) { try { - if (!model || !model.icContentTypeAlias) return false; - if (!$scope.model.config.contentTypes.filter(x => x.icContentTypeAlias === model.icContentTypeAlias).length) return false; + if (!model || !model.icContentTypeGuid) return false; + if (!$scope.model.config.contentTypes.filter(x => x.icContentTypeGuid === model.icContentTypeGuid).length) return false; return true; } catch (e) { return false; From 6551bde7edf1498e406ce91af595a932952f0b03 Mon Sep 17 00:00:00 2001 From: leekelleher Date: Thu, 19 Apr 2018 17:24:11 +0100 Subject: [PATCH 07/29] When pasting the item, it is added to the stack. It doesn't open the overlay panel. --- .../StackedContent/js/stackedcontent.controllers.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js index b1314cc..7638597 100644 --- a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js +++ b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js @@ -77,9 +77,7 @@ return; } if (validateModel(stackedContentItem)) { - $scope.overlayConfig.event = evt; - $scope.overlayConfig.data = { model: stackedContentItem, idx: idx, action: "add" }; - $scope.overlayConfig.show = true; + $scope.overlayConfig.callback({ model: stackedContentItem, idx: idx, action: "add" }); return; } else { notificationsService.error("Stacked Content", "Sorry, this content is not allowed here."); From c4d47f59d6e2790ac219b463ecddf87e89696370 Mon Sep 17 00:00:00 2001 From: leekelleher Date: Thu, 19 Apr 2018 19:07:23 +0100 Subject: [PATCH 08/29] Bumped version number to v2.0.0-alpha --- appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 1a88947..e1581c3 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,12 +1,12 @@ image: Visual Studio 2017 # version format -version: 1.1.1.{build} +version: 2.0.0.{build} # UMBRACO_PACKAGE_PRERELEASE_SUFFIX if a rtm release build this should be blank, otherwise if empty will default to alpha # example UMBRACO_PACKAGE_PRERELEASE_SUFFIX=beta init: - - set UMBRACO_PACKAGE_PRERELEASE_SUFFIX= + - set UMBRACO_PACKAGE_PRERELEASE_SUFFIX=alpha cache: - src\packages -> **\packages.config # preserve "packages" directory in the root of build folder but will reset it if packages.config is modified From 4866998630e8a539820cc7f95d202f738e6d18e1 Mon Sep 17 00:00:00 2001 From: leekelleher Date: Thu, 19 Apr 2018 19:01:42 +0100 Subject: [PATCH 09/29] [WIP] Copy/paste feature amends --- .../js/stackedcontent.controllers.js | 49 +++++++++---------- .../StackedContent/views/stackedcontent.html | 6 +-- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js index 7ca75bb..9bea038 100644 --- a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js +++ b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js @@ -22,21 +22,18 @@ }; $scope.canCopy = function () { - var test = "test"; try { - window.localStorage.setItem(test, test); - window.localStorage.removeItem(test); - return true; + return !!sessionStorage.getItem; } catch (e) { return false; } - } + }; $scope.canPaste = function () { - var stackedContentItem = JSON.parse(window.localStorage.getItem("StackedContentCopy")); - if (stackedContentItem && validateModel(stackedContentItem)) return true; + var item = JSON.parse(window.localStorage.getItem("InnerContent_CopiedItems")); + if (item && validateModel(item)) return true; return false; - } + }; $scope.addContent = function (evt, idx) { $scope.overlayConfig.event = evt; @@ -55,34 +52,34 @@ setDirty(); }; - $scope.copyToLocalStorage = function (evt, idx) { - var stackedContentItem = JSON.parse(JSON.stringify($scope.model.value[idx])); - stackedContentItem.key = ""; - delete stackedContentItem.$$hashKey; + $scope.copyContent = function (evt, idx) { + var item = JSON.parse(JSON.stringify($scope.model.value[idx])); + item.key = ""; + delete item.$$hashKey; - if (validateModel(stackedContentItem)) { - window.localStorage.setItem("StackedContentCopy", JSON.stringify(stackedContentItem)); - notificationsService.success("Stacked Content", "Copied to clipboard."); + if (validateModel(item)) { + window.localStorage.setItem("InnerContent_CopiedItems", JSON.stringify(item)); + notificationsService.success("Content", "Content block copied to clipboard."); return; } else { - notificationsService.error("Stacked Content", "Sorry, something went wrong."); + notificationsService.error("Content", "Unfortunately, the content block was not able to be copied."); } - } + }; - $scope.pasteFromLocalStorage = function (evt, idx) { - var stackedContentItem = JSON.parse(window.localStorage.getItem("StackedContentCopy")); - stackedContentItem.key = innerContentService.generateUid(); - if (!stackedContentItem) { - notificationsService.error("Stacked Content", "You need to copy content first."); + $scope.pasteContent = function (evt, idx) { + var item = JSON.parse(window.localStorage.getItem("InnerContent_CopiedItems")); + item.key = innerContentService.generateUid(); + if (!item) { + notificationsService.error("Content", "Please copy a content block before attempting to paste it."); return; } - if (validateModel(stackedContentItem)) { - $scope.overlayConfig.callback({ model: stackedContentItem, idx: idx, action: "add" }); + if (validateModel(item)) { + $scope.overlayConfig.callback({ model: item, idx: idx, action: "add" }); return; } else { - notificationsService.error("Stacked Content", "Sorry, this content is not allowed here."); + notificationsService.error("Content", "Unfortunately, the content block is not allowed to be pasted here."); } - } + }; $scope.sortableOptions = { axis: 'y', diff --git a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/views/stackedcontent.html b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/views/stackedcontent.html index df87783..621a30f 100644 --- a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/views/stackedcontent.html +++ b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/views/stackedcontent.html @@ -15,7 +15,7 @@
- +
@@ -27,7 +27,7 @@

{{itm.name}}

- + {{itm.name}}
- +
From 07368fefc1d75b4408bebb3c43b938fbe181c747 Mon Sep 17 00:00:00 2001 From: leekelleher Date: Mon, 23 Apr 2018 14:49:04 +0100 Subject: [PATCH 10/29] Enabled paste button for empty Stacks --- .../Web/UI/App_Plugins/StackedContent/css/stackedcontent.css | 4 ++++ .../UI/App_Plugins/StackedContent/views/stackedcontent.html | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/css/stackedcontent.css b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/css/stackedcontent.css index f2b2463..f9fa7f1 100644 --- a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/css/stackedcontent.css +++ b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/css/stackedcontent.css @@ -83,6 +83,10 @@ color: #00aea2; } +.stacked-content .placeholder a:hover { + text-decoration: none; +} + .stack__buttons { position: absolute; right: -12px; diff --git a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/views/stackedcontent.html b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/views/stackedcontent.html index 621a30f..3a58baa 100644 --- a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/views/stackedcontent.html +++ b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/views/stackedcontent.html @@ -4,9 +4,10 @@
- +
- + +
From 3b19f86f9af47c09b9254f4d4a8119a70685f973 Mon Sep 17 00:00:00 2001 From: leekelleher Date: Mon, 23 Apr 2018 14:49:57 +0100 Subject: [PATCH 11/29] Fixed type-value bug with the `maxItems` check --- .../App_Plugins/StackedContent/js/stackedcontent.controllers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js index 9bea038..368b902 100644 --- a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js +++ b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js @@ -14,7 +14,7 @@ $scope.model.value = $scope.model.value || []; $scope.canAdd = function () { - return (!$scope.model.config.maxItems || $scope.model.config.maxItems === 0 || $scope.model.value.length < $scope.model.config.maxItems) && $scope.model.config.singleItemMode !== "1"; + return (!$scope.model.config.maxItems || $scope.model.config.maxItems === "0" || $scope.model.value.length < $scope.model.config.maxItems) && $scope.model.config.singleItemMode !== "1"; }; $scope.canDelete = function () { From f2919576439848f402b6986128ad4e3898c42b58 Mon Sep 17 00:00:00 2001 From: leekelleher Date: Mon, 23 Apr 2018 14:54:22 +0100 Subject: [PATCH 12/29] Copy/Paste refactorings - Replaced the `window.localStorage` calls with the `localStorageService` (which is used by Umbraco core and has built-in fallbacks) - Replaced emptying the "key" and removing the "$$hashKey" properties to the `stringify` function - Reworked the `canPaste` function, as it was being evaluated several times, when the value could be referenced in a local field variable - Reduced the "Is Content Validate" function, it was over-working - Set the dirty flag, after pasting content - Added (temporary) TODO notes --- .../js/stackedcontent.controllers.js | 73 +++++++++++-------- 1 file changed, 42 insertions(+), 31 deletions(-) diff --git a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js index 368b902..5431192 100644 --- a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js +++ b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js @@ -3,16 +3,21 @@ "$scope", "editorState", "notificationsService", + "localStorageService", "innerContentService", "Our.Umbraco.StackedContent.Resources.StackedContentResources", - function ($scope, editorState, notificationsService, innerContentService, scResources) { + function ($scope, editorState, notificationsService, localStorageService, innerContentService, scResources) { $scope.inited = false; $scope.markup = {}; $scope.prompts = {}; $scope.model.value = $scope.model.value || []; + $scope.contentTypeGuids = _.uniq($scope.model.config.contentTypes.map(function (itm) { + return itm.icContentTypeGuid; + })); + $scope.canAdd = function () { return (!$scope.model.config.maxItems || $scope.model.config.maxItems === "0" || $scope.model.value.length < $scope.model.config.maxItems) && $scope.model.config.singleItemMode !== "1"; }; @@ -22,16 +27,14 @@ }; $scope.canCopy = function () { - try { - return !!sessionStorage.getItem; - } catch (e) { - return false; - } + // TODO: Move this to InnerContent Service + return localStorageService.isSupported; }; $scope.canPaste = function () { - var item = JSON.parse(window.localStorage.getItem("InnerContent_CopiedItems")); - if (item && validateModel(item)) return true; + if ($scope.canCopy() && $scope.canAdd()) { + return allowPaste; + } return false; }; @@ -53,29 +56,30 @@ }; $scope.copyContent = function (evt, idx) { - var item = JSON.parse(JSON.stringify($scope.model.value[idx])); - item.key = ""; - delete item.$$hashKey; - - if (validateModel(item)) { - window.localStorage.setItem("InnerContent_CopiedItems", JSON.stringify(item)); - notificationsService.success("Content", "Content block copied to clipboard."); - return; + // TODO: Move this to InnerContent Service + var item = $scope.model.value[idx]; + if (item && item.icContentTypeGuid) { + localStorageService.set("icContentJson", JSON.stringify(item, function (k, v) { + if (k === "key" || k === "$$hashKey") { + return undefined; + } + return v; + })); + allowPaste = true; + notificationsService.success("Content", "The content block has been copied."); } else { notificationsService.error("Content", "Unfortunately, the content block was not able to be copied."); } }; $scope.pasteContent = function (evt, idx) { - var item = JSON.parse(window.localStorage.getItem("InnerContent_CopiedItems")); + // TODO: Move this to InnerContent Service + var item = JSON.parse(localStorageService.get("icContentJson")); item.key = innerContentService.generateUid(); - if (!item) { - notificationsService.error("Content", "Please copy a content block before attempting to paste it."); - return; - } - if (validateModel(item)) { + + if (contentValid(item)) { $scope.overlayConfig.callback({ model: item, idx: idx, action: "add" }); - return; + setDirty(); } else { notificationsService.error("Content", "Unfortunately, the content block is not allowed to be pasted here."); } @@ -120,15 +124,22 @@ } }; - var validateModel = function (model) { - try { - if (!model || !model.icContentTypeGuid) return false; - if (!$scope.model.config.contentTypes.filter(x => x.icContentTypeGuid === model.icContentTypeGuid).length) return false; - return true; - } catch (e) { - return false; + var contentValid = function (itm) { + return !!itm && !!itm.icContentTypeGuid && _.contains($scope.contentTypeGuids, itm.icContentTypeGuid); + }; + + var pasteAllowed = function () { + // TODO: Move this to InnerContent Service + var json = localStorageService.get("icContentJson"); + if (json !== null) { + var item = JSON.parse(json); + return item && contentValid(item); } - } + return false; + }; + + // Storing the 'canPaste' check in a local variable, so that it doesn't need to be re-eval'd every time + var allowPaste = pasteAllowed(); // Set overlay config $scope.overlayConfig = { From b0e3d357ac4d78a1a7abda8f9dae5d36c1922d89 Mon Sep 17 00:00:00 2001 From: leekelleher Date: Tue, 8 May 2018 22:52:41 +0100 Subject: [PATCH 13/29] Added placeholder comments for future `innerContentService` calls --- .../js/stackedcontent.controllers.js | 19 ++++++++++++------- .../StackedContent/views/stackedcontent.html | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js index 5431192..7273ad7 100644 --- a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js +++ b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js @@ -28,11 +28,12 @@ $scope.canCopy = function () { // TODO: Move this to InnerContent Service - return localStorageService.isSupported; + return localStorageService.isSupported; // innerContentService.canCopyContent(); }; $scope.canPaste = function () { - if ($scope.canCopy() && $scope.canAdd()) { + //if (innerContentService.canPasteContent() && $scope.canAdd()) { + if (localStorageService.isSupported && $scope.canAdd()) { return allowPaste; } return false; @@ -56,8 +57,10 @@ }; $scope.copyContent = function (evt, idx) { - // TODO: Move this to InnerContent Service var item = $scope.model.value[idx]; + // TODO: Move this to InnerContent Service + // var success = innerContentService.setCopiedContent(item); + // if (success) { if (item && item.icContentTypeGuid) { localStorageService.set("icContentJson", JSON.stringify(item, function (k, v) { if (k === "key" || k === "$$hashKey") { @@ -74,10 +77,11 @@ $scope.pasteContent = function (evt, idx) { // TODO: Move this to InnerContent Service + // var item = innerContentService.getCopiedContent(); var item = JSON.parse(localStorageService.get("icContentJson")); item.key = innerContentService.generateUid(); - if (contentValid(item)) { + if (item && contentTypeGuidIsAllowed(item.icContentTypeGuid)) { $scope.overlayConfig.callback({ model: item, idx: idx, action: "add" }); setDirty(); } else { @@ -124,16 +128,17 @@ } }; - var contentValid = function (itm) { - return !!itm && !!itm.icContentTypeGuid && _.contains($scope.contentTypeGuids, itm.icContentTypeGuid); + var contentTypeGuidIsAllowed = function (guid) { + return !!guid && _.contains($scope.contentTypeGuids, guid); }; var pasteAllowed = function () { // TODO: Move this to InnerContent Service + // var guid = innerContentService.getCopiedContentTypeGuid(); var json = localStorageService.get("icContentJson"); if (json !== null) { var item = JSON.parse(json); - return item && contentValid(item); + return item && contentTypeGuidIsAllowed(item.icContentTypeGuid); } return false; }; diff --git a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/views/stackedcontent.html b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/views/stackedcontent.html index 3a58baa..0b51ba9 100644 --- a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/views/stackedcontent.html +++ b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/views/stackedcontent.html @@ -4,7 +4,7 @@
-
+
From d21d66e2c29d8dcccec29bdf4084a8ca903390a1 Mon Sep 17 00:00:00 2001 From: leekelleher Date: Tue, 8 May 2018 23:40:42 +0100 Subject: [PATCH 14/29] Removed the extra JSON serialization/deserialization as localStorageService handles this (and angular.toJson removes the "$$haskKey" property) --- .../js/stackedcontent.controllers.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js index 7273ad7..084cec6 100644 --- a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js +++ b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js @@ -62,12 +62,8 @@ // var success = innerContentService.setCopiedContent(item); // if (success) { if (item && item.icContentTypeGuid) { - localStorageService.set("icContentJson", JSON.stringify(item, function (k, v) { - if (k === "key" || k === "$$hashKey") { - return undefined; - } - return v; - })); + item.key = undefined; + localStorageService.set("icContentJson", item); allowPaste = true; notificationsService.success("Content", "The content block has been copied."); } else { @@ -78,7 +74,7 @@ $scope.pasteContent = function (evt, idx) { // TODO: Move this to InnerContent Service // var item = innerContentService.getCopiedContent(); - var item = JSON.parse(localStorageService.get("icContentJson")); + var item = localStorageService.get("icContentJson"); item.key = innerContentService.generateUid(); if (item && contentTypeGuidIsAllowed(item.icContentTypeGuid)) { @@ -135,9 +131,8 @@ var pasteAllowed = function () { // TODO: Move this to InnerContent Service // var guid = innerContentService.getCopiedContentTypeGuid(); - var json = localStorageService.get("icContentJson"); - if (json !== null) { - var item = JSON.parse(json); + var item = localStorageService.get("icContentJson"); + if (item !== null) { return item && contentTypeGuidIsAllowed(item.icContentTypeGuid); } return false; From faf4aff150963ca122cc35bb38ae2a59a243af2e Mon Sep 17 00:00:00 2001 From: leekelleher Date: Wed, 30 May 2018 17:40:12 +0100 Subject: [PATCH 15/29] Makes a copy of the JSON data, rather than copying the reference. Thanks to @markadrake for spotting this! https://github.com/umco/umbraco-stacked-content/pull/44#issuecomment-393218403 --- .../App_Plugins/StackedContent/js/stackedcontent.controllers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js index 084cec6..7e6ff92 100644 --- a/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js +++ b/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.controllers.js @@ -57,7 +57,7 @@ }; $scope.copyContent = function (evt, idx) { - var item = $scope.model.value[idx]; + var item = JSON.parse(JSON.stringify($scope.model.value[idx])); // TODO: Move this to InnerContent Service // var success = innerContentService.setCopiedContent(item); // if (success) { From 2b019fa63bc09ad3bfbda4c1f42153b8d59846fb Mon Sep 17 00:00:00 2001 From: leekelleher Date: Mon, 2 Jul 2018 14:44:32 +0100 Subject: [PATCH 16/29] Bug fix, for when attempting to preview on a new content page --- .../Controllers/StackedContentApiController.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Our.Umbraco.StackedContent/Web/Controllers/StackedContentApiController.cs b/src/Our.Umbraco.StackedContent/Web/Controllers/StackedContentApiController.cs index f0a148a..cf21cb0 100644 --- a/src/Our.Umbraco.StackedContent/Web/Controllers/StackedContentApiController.cs +++ b/src/Our.Umbraco.StackedContent/Web/Controllers/StackedContentApiController.cs @@ -6,6 +6,7 @@ using Our.Umbraco.InnerContent.Helpers; using Our.Umbraco.StackedContent.Models; using Our.Umbraco.StackedContent.Web.Helpers; +using Umbraco.Core.Models; using Umbraco.Web.Mvc; using Umbraco.Web.WebApi; @@ -17,12 +18,18 @@ public class StackedContentApiController : UmbracoAuthorizedApiController [HttpPost] public HttpResponseMessage GetPreviewMarkup([FromBody] JObject item, int pageId) { - // Get page container node - var page = UmbracoContext.ContentCache.GetById(pageId); - if (page == null) + var page = default(IPublishedContent); + + // If the page is new, then the ID will be zero + if (pageId > 0) { - // If unpublished, then fake PublishedContent (with IContent object) - page = new UnpublishedContent(pageId, Services); + // Get page container node + page = UmbracoContext.ContentCache.GetById(pageId); + if (page == null) + { + // If unpublished, then fake PublishedContent (with IContent object) + page = new UnpublishedContent(pageId, Services); + } } // Convert item From 8afecee6da88bc337049898f470c4ed0178c8f4e Mon Sep 17 00:00:00 2001 From: leekelleher Date: Mon, 2 Jul 2018 15:10:49 +0100 Subject: [PATCH 17/29] Upgraded InnerContent assembly reference to v2.0.0-alpha Using NuGet.config to define AppVeyor CI builds as the package source (since v1.x-develop already builds to MyGet) Upgraded UmbracoCms.Core to v7.7.0 (to match InnerContent) --- src/NuGet.config | 6 + src/Our.Umbraco.StackedContent.sln | 9 + .../Our.Umbraco.StackedContent.csproj | 215 +----------------- src/Our.Umbraco.StackedContent/app.config | 12 +- .../packages.config | 35 +-- 5 files changed, 56 insertions(+), 221 deletions(-) create mode 100644 src/NuGet.config diff --git a/src/NuGet.config b/src/NuGet.config new file mode 100644 index 0000000..f0f43a2 --- /dev/null +++ b/src/NuGet.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/Our.Umbraco.StackedContent.sln b/src/Our.Umbraco.StackedContent.sln index dd0d978..b67daab 100644 --- a/src/Our.Umbraco.StackedContent.sln +++ b/src/Our.Umbraco.StackedContent.sln @@ -23,6 +23,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build Scripts", "Build Scri ..\build\package.xml = ..\build\package.xml EndProjectSection EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NuGet", "NuGet", "{5F00E80B-E36C-4E38-AA70-674B10FCEDBF}" + ProjectSection(SolutionItems) = preProject + NuGet.config = NuGet.config + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -39,5 +44,9 @@ Global EndGlobalSection GlobalSection(NestedProjects) = preSolution {95F00400-1FCA-4D98-9643-ACBC2203C1D0} = {52A49C4D-441F-4D54-A23F-444AF47DB250} + {5F00E80B-E36C-4E38-AA70-674B10FCEDBF} = {52A49C4D-441F-4D54-A23F-444AF47DB250} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {8EB27366-AEDB-4CCA-BA9F-287BD20233E9} EndGlobalSection EndGlobal diff --git a/src/Our.Umbraco.StackedContent/Our.Umbraco.StackedContent.csproj b/src/Our.Umbraco.StackedContent/Our.Umbraco.StackedContent.csproj index 46c8110..bad55fc 100644 --- a/src/Our.Umbraco.StackedContent/Our.Umbraco.StackedContent.csproj +++ b/src/Our.Umbraco.StackedContent/Our.Umbraco.StackedContent.csproj @@ -30,229 +30,35 @@ 4 - - ..\packages\AutoMapper.3.0.0\lib\net40\AutoMapper.dll + + ..\packages\UmbracoCms.Core.7.7.0\lib\net45\interfaces.dll False - - ..\packages\AutoMapper.3.0.0\lib\net40\AutoMapper.Net4.dll + + ..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll False - - ..\packages\UmbracoCms.Core.7.4.0\lib\businesslogic.dll - False - - - ..\packages\ClientDependency.1.8.4\lib\net45\ClientDependency.Core.dll - False - - - ..\packages\ClientDependency-Mvc5.1.8.0.0\lib\net45\ClientDependency.Core.Mvc.dll - False - - - ..\packages\UmbracoCms.Core.7.4.0\lib\cms.dll - False - - - ..\packages\UmbracoCms.Core.7.4.0\lib\controls.dll - False - - - ..\packages\xmlrpcnet.2.5.0\lib\net20\CookComputing.XmlRpcV2.dll - False - - - ..\packages\Examine.0.1.68.0\lib\Examine.dll - False - - - ..\packages\HtmlAgilityPack.1.4.9\lib\Net45\HtmlAgilityPack.dll - False - - - ..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll - False - - - ..\packages\ImageProcessor.2.3.3.0\lib\net45\ImageProcessor.dll - False - - - ..\packages\ImageProcessor.Web.4.5.3.0\lib\net45\ImageProcessor.Web.dll - False - - - ..\packages\UmbracoCms.Core.7.4.0\lib\interfaces.dll - False - - - ..\packages\UmbracoCms.Core.7.4.0\lib\log4net.dll - False - - - ..\packages\Lucene.Net.2.9.4.1\lib\net40\Lucene.Net.dll - False - - - ..\packages\Markdown.1.14.4\lib\net45\MarkdownSharp.dll - False - - - ..\packages\UmbracoCms.Core.7.4.0\lib\Microsoft.ApplicationBlocks.Data.dll - False - - - ..\packages\Microsoft.AspNet.Identity.Core.2.2.1\lib\net45\Microsoft.AspNet.Identity.Core.dll - False - - - ..\packages\Microsoft.AspNet.Identity.Owin.2.2.1\lib\net45\Microsoft.AspNet.Identity.Owin.dll - False - - - ..\packages\Microsoft.Owin.3.0.1\lib\net45\Microsoft.Owin.dll - False - - - ..\packages\Microsoft.Owin.Host.SystemWeb.3.0.1\lib\net45\Microsoft.Owin.Host.SystemWeb.dll - False - - - ..\packages\Microsoft.Owin.Security.3.0.1\lib\net45\Microsoft.Owin.Security.dll - False - - - ..\packages\Microsoft.Owin.Security.Cookies.3.0.1\lib\net45\Microsoft.Owin.Security.Cookies.dll - False - - - ..\packages\Microsoft.Owin.Security.OAuth.3.0.1\lib\net45\Microsoft.Owin.Security.OAuth.dll - False - - - ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll - False - - - ..\packages\MiniProfiler.2.1.0\lib\net40\MiniProfiler.dll - False - - - ..\packages\MySql.Data.6.9.9\lib\net45\MySql.Data.dll - False - - - ..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll - False - - - ..\packages\Our.Umbraco.InnerContent.Core.1.1.0\lib\net45\Our.Umbraco.InnerContent.dll - - - ..\packages\Owin.1.0\lib\net40\Owin.dll - False - - - ..\packages\semver.1.1.2\lib\net451\Semver.dll - False - - - ..\packages\UmbracoCms.Core.7.4.0\lib\SQLCE4Umbraco.dll + + ..\packages\Our.Umbraco.InnerContent.Core.2.0.0-alpha-000131\lib\net45\Our.Umbraco.InnerContent.dll False - - - ..\packages\UmbracoCms.Core.7.4.0\lib\System.Data.SqlServerCe.dll - False - - - ..\packages\UmbracoCms.Core.7.4.0\lib\System.Data.SqlServerCe.Entity.dll - False - - - ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll - False - - - - ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.Helpers.dll - False - ..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll False - - ..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.3\lib\net45\System.Web.Http.WebHost.dll - False - ..\packages\Microsoft.AspNet.Mvc.5.2.3\lib\net45\System.Web.Mvc.dll False - - ..\packages\Microsoft.AspNet.Razor.3.2.3\lib\net45\System.Web.Razor.dll - False - - - ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.dll - False - - - ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Deployment.dll - False - - - ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Razor.dll - False - - - - - - - - ..\packages\UmbracoCms.Core.7.4.0\lib\TidyNet.dll - False - - - ..\packages\UmbracoCms.Core.7.4.0\lib\umbraco.dll - False - - - ..\packages\UmbracoCms.Core.7.4.0\lib\Umbraco.Core.dll - False - - - ..\packages\UmbracoCms.Core.7.4.0\lib\umbraco.DataLayer.dll - False - - - ..\packages\UmbracoCms.Core.7.4.0\lib\umbraco.editorControls.dll - False - - - ..\packages\UmbracoCms.Core.7.4.0\lib\umbraco.MacroEngines.dll - False - - - ..\packages\UmbracoCms.Core.7.4.0\lib\umbraco.providers.dll - False - - - ..\packages\UmbracoCms.Core.7.4.0\lib\Umbraco.Web.UI.dll - False - - - ..\packages\UmbracoCms.Core.7.4.0\lib\UmbracoExamine.dll + + ..\packages\UmbracoCms.Core.7.7.0\lib\net45\umbraco.dll False - - ..\packages\UrlRewritingNet.2.0.7\lib\UrlRewritingNet.UrlRewriter.dll + + ..\packages\UmbracoCms.Core.7.7.0\lib\net45\Umbraco.Core.dll False @@ -288,6 +94,7 @@ ) ) +