Get Entity by Query WIP
This commit is contained in:
@@ -99,6 +99,16 @@ function entityResource($q, $http, umbRequestHelper) {
|
||||
'Failed to retreive entity data for id ' + id);
|
||||
},
|
||||
|
||||
getByQuery: function (query, rootNodeId, type) {
|
||||
return umbRequestHelper.resourcePromise(
|
||||
$http.get(
|
||||
umbRequestHelper.getApiUrl(
|
||||
"entityApiBaseUrl",
|
||||
"GetByQuery",
|
||||
[{query: query},{ rootNodeId: rootNodeId}, {type: type }])),
|
||||
'Failed to retreive entity data for query ' + query);
|
||||
},
|
||||
|
||||
/**
|
||||
* @ngdoc method
|
||||
* @name umbraco.resources.entityResource#getByIds
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
angular.module('umbraco')
|
||||
.controller("Umbraco.PropertyEditors.ContentPickerController",
|
||||
|
||||
function($scope, dialogService, entityResource, $log, iconHelper){
|
||||
function($scope, dialogService, entityResource, editorState, $log, iconHelper){
|
||||
$scope.renderModel = [];
|
||||
$scope.ids = $scope.model.value ? $scope.model.value.split(',') : [];
|
||||
|
||||
@@ -11,6 +11,8 @@ angular.module('umbraco')
|
||||
$scope.cfg = {
|
||||
multiPicker: "0",
|
||||
entityType: "Document",
|
||||
filterCssClass: "not-allowed not-published",
|
||||
|
||||
startNode:{
|
||||
type: "content",
|
||||
id: -1
|
||||
@@ -31,11 +33,23 @@ angular.module('umbraco')
|
||||
$scope.cfg.entityType = "Media";
|
||||
}
|
||||
|
||||
//if we have a query for the startnode, we will use that.
|
||||
if($scope.cfg.startNode.query){
|
||||
var rootId = -1;
|
||||
if($scope.cfg.startNode.scope === "current"){
|
||||
rootId = editorState.current.id;
|
||||
}
|
||||
|
||||
entityResource.getByQuery($scope.cfg.startNode.query, rootId, "Document").then(function(ent){
|
||||
$scope.cfg.startNodeId = ent.id;
|
||||
});
|
||||
}else{
|
||||
$scope.cfg.startNodeId = $scope.cfg.startNode.id;
|
||||
}
|
||||
|
||||
$scope.cfg.callback = populate;
|
||||
$scope.cfg.treeAlias = $scope.cfg.startNode.type;
|
||||
$scope.cfg.section = $scope.cfg.startNode.type;
|
||||
$scope.cfg.startNodeId = $scope.cfg.startNode.id;
|
||||
$scope.cfg.filterCssClass = "not-allowed not-published";
|
||||
$scope.cfg.section = $scope.cfg.startNode.type;
|
||||
|
||||
//load current data
|
||||
entityResource.getByIds($scope.ids, $scope.cfg.entityType).then(function(data){
|
||||
|
||||
@@ -25,6 +25,7 @@ using Examine;
|
||||
using Examine.LuceneEngine.SearchCriteria;
|
||||
using Examine.SearchCriteria;
|
||||
using Umbraco.Web.Dynamics;
|
||||
using umbraco;
|
||||
|
||||
namespace Umbraco.Web.Editors
|
||||
{
|
||||
@@ -128,6 +129,45 @@ namespace Umbraco.Web.Editors
|
||||
return GetResultForKey(id, type);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an entity by a xpath or css-like query
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
public EntityBasic GetByQuery(string query, int rootNodeId, UmbracoEntityTypes type)
|
||||
{
|
||||
|
||||
//this is css (commented out for now, due to external dependency)
|
||||
//if (!query.Contains("::") && !query.Contains('/'))
|
||||
// query = css2xpath.Converter.CSSToXPath(query, "");
|
||||
|
||||
|
||||
if(rootNodeId < 0){
|
||||
var nodes = global::umbraco.library.GetXmlNodeByXPath(query);
|
||||
var node = uQuery.GetNodesByXPath(query).FirstOrDefault();
|
||||
|
||||
if(node == null)
|
||||
return null;
|
||||
|
||||
return GetById(node.Id, UmbracoEntityTypes.Document);
|
||||
}else{
|
||||
var node = global::umbraco.library.GetXmlNodeById(rootNodeId.ToString());
|
||||
if (node.MoveNext())
|
||||
{
|
||||
if (node.Current != null)
|
||||
{
|
||||
var result = node.Current.Select(query);
|
||||
//set it to the first node found (if there is one), otherwise to -1
|
||||
if (result.Current != null)
|
||||
return GetById(int.Parse(result.Current.GetAttribute("id", string.Empty)), UmbracoEntityTypes.Document);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public EntityBasic GetById(int id, UmbracoEntityTypes type)
|
||||
{
|
||||
return GetResultForId(id, type);
|
||||
|
||||
Reference in New Issue
Block a user