From 8136b3ecb0459ca9a750c03886eebebf10d5017c Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 8 Oct 2014 19:03:45 +1100 Subject: [PATCH] Got searching working from a particular node id, got the UI nearly working --- .../src/common/resources/entity.resource.js | 4 +- .../common/dialogs/memberpicker.controller.js | 2 + .../common/dialogs/treepicker.controller.js | 51 +++++++++++-------- .../src/views/common/dialogs/treepicker.html | 22 ++++---- src/Umbraco.Web/Editors/EntityController.cs | 8 +-- 5 files changed, 50 insertions(+), 37 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/entity.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/entity.resource.js index eeb81f2d67..e851f873b0 100644 --- a/src/Umbraco.Web.UI.Client/src/common/resources/entity.resource.js +++ b/src/Umbraco.Web.UI.Client/src/common/resources/entity.resource.js @@ -263,14 +263,14 @@ function entityResource($q, $http, umbRequestHelper) { * @returns {Promise} resourcePromise object containing the entity array. * */ - search: function (query, type) { + search: function (query, type, startNodeId) { return umbRequestHelper.resourcePromise( $http.get( umbRequestHelper.getApiUrl( "entityApiBaseUrl", "Search", - [{ query: query }, {type: type}])), + [{ query: query }, { type: type }, { startNodeId: startNodeId }])), 'Failed to retrieve entity data for query ' + query); }, diff --git a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/memberpicker.controller.js b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/memberpicker.controller.js index f77f63dd05..cddddd5f9f 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/memberpicker.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/memberpicker.controller.js @@ -30,6 +30,8 @@ angular.module("umbraco").controller("Umbraco.Dialogs.MemberPickerController", } } + + //TODO: This needs debounce! $scope.performSearch = function() { if ($scope.term) { if ($scope.oldTerm !== $scope.term) { diff --git a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/treepicker.controller.js b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/treepicker.controller.js index 9601ca649a..d25e4ff310 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/treepicker.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/treepicker.controller.js @@ -7,12 +7,20 @@ angular.module("umbraco").controller("Umbraco.Dialogs.TreePickerController", $scope.section = dialogOptions.section; $scope.treeAlias = dialogOptions.treeAlias; $scope.multiPicker = dialogOptions.multiPicker; - $scope.hideHeader = true; - $scope.startNodeId = dialogOptions.startNodeId ? dialogOptions.startNodeId : -1; + $scope.hideHeader = true; localizationService.localize("general_typeToSearch").then(function (value) { $scope.searchPlaceholderText = value; }); - $scope.selectedSearchResults = []; + $scope.searchInfo = { + selectedSearchResults: [], + searchStartNodeId: null, + searchStartNodeName: null, + showSearch: false, + term: null, + oldTerm: null, + results: [] + } + //create the custom query string param for this tree $scope.customTreeParams = dialogOptions.startNodeId ? "startNodeId=" + dialogOptions.startNodeId : ""; $scope.customTreeParams += dialogOptions.customTreeParams ? "&" + dialogOptions.customTreeParams : ""; @@ -59,8 +67,9 @@ angular.module("umbraco").controller("Umbraco.Dialogs.TreePickerController", function nodeSearchHandler(ev, args) { if (args.node.metaData.isContainer === true) { - $scope.showSearch = true; - $scope.searchSubHeader = args.node.name; + $scope.searchInfo.showSearch = true; + $scope.searchInfo.searchStartNodeName = args.node.name; + $scope.searchInfo.searchStartNodeId = args.node.id; } } @@ -99,7 +108,7 @@ angular.module("umbraco").controller("Umbraco.Dialogs.TreePickerController", if ($scope.multiPicker) { $scope.select(id); - if (!$scope.searchSubHeader) { + if (!$scope.searchInfo.searchStartNodeId) { $scope.hideSearch(); } } @@ -161,32 +170,34 @@ angular.module("umbraco").controller("Umbraco.Dialogs.TreePickerController", }; $scope.hideSearch = function() { - $scope.showSearch = false; - $scope.searchSubHeader = null; - $scope.term = ""; - $scope.oldTerm = ""; - $scope.results = []; + $scope.searchInfo.showSearch = false; + $scope.searchInfo.searchStartNodeName = null; + $scope.searchInfo.searchStartNodeId = null; + $scope.searchInfo.term = null; + $scope.searchInfo.oldTerm = null; + $scope.searchInfo.results = []; } //handles the on key up for searching, but we don't want to over query so the result is debounced $scope.performSearch = _.debounce(function () { angularHelper.safeApply($scope, function() { - if ($scope.term) { - if ($scope.oldTerm !== $scope.term) { - $scope.results = []; + if ($scope.searchInfo.term) { + if ($scope.searchInfo.oldTerm !== $scope.searchInfo.term) { + $scope.searchInfo.results = []; var searchArgs = { - term: $scope.term + term: $scope.searchInfo.term }; - if (dialogOptions.startNodeId) { - searchArgs["startNodeId"] = dialogOptions.startNodeId; + //append a start node id, whether it's a global one, or based on a selected list view + if ($scope.searchInfo.searchStartNodeId || dialogOptions.startNodeId) { + searchArgs["startNodeId"] = $scope.searchInfo.searchStartNodeId ? $scope.searchInfo.searchStartNodeId : dialogOptions.startNodeId; } searcher(searchArgs).then(function (data) { - $scope.results = data; + $scope.searchInfo.results = data; }); - $scope.showSearch = true; - $scope.oldTerm = $scope.term; + $scope.searchInfo.showSearch = true; + $scope.searchInfo.oldTerm = $scope.searchInfo.term; } } else { diff --git a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/treepicker.html b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/treepicker.html index 42ddf4608c..94429f8f24 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/treepicker.html +++ b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/treepicker.html @@ -2,25 +2,25 @@