get url for items + set published/unpublished state

This commit is contained in:
Mads Rasmussen
2017-01-16 14:45:50 +01:00
parent 198edec4f4
commit 3bdc2e63ab
7 changed files with 140 additions and 38 deletions

View File

@@ -15,6 +15,7 @@
icon: "=?",
name: "=",
description: "=?",
published: "=?",
sortable: "=?",
allowOpen: "=?",
allowRemove: "=?",

View File

@@ -56,7 +56,7 @@ function entityResource($q, $http, umbRequestHelper) {
*
* ##usage
* <pre>
* entityResource.getPath(id)
* entityResource.getPath(id, type)
* .then(function(pathArray) {
* alert('its here!');
* });
@@ -77,6 +77,37 @@ function entityResource($q, $http, umbRequestHelper) {
'Failed to retrieve path for id:' + id);
},
/**
* @ngdoc method
* @name umbraco.resources.entityResource#getUrl
* @methodOf umbraco.resources.entityResource
*
* @description
* Returns a url, given a node ID and type
*
* ##usage
* <pre>
* entityResource.getUrl(id, type)
* .then(function(url) {
* alert('its here!');
* });
* </pre>
*
* @param {Int} id Id of node to return the public url to
* @param {string} type Object type name
* @returns {Promise} resourcePromise object containing the url.
*
*/
getUrl: function(id, type) {
return umbRequestHelper.resourcePromise(
$http.get(
umbRequestHelper.getApiUrl(
"entityApiBaseUrl",
"GetUrl",
[{ id: id }, {type: type }])),
'Failed to retrieve url for id:' + id);
},
/**
* @ngdoc method
* @name umbraco.resources.entityResource#getById
@@ -140,7 +171,7 @@ function entityResource($q, $http, umbRequestHelper) {
query += "ids=" + item + "&";
});
// if ids array is empty we need a empty variable in the querystring otherwise the service returns a error
// if ids array is empty we need a empty variable in the querystring otherwise the service returns a error
if (ids.length === 0) {
query += "ids=&";
}

View File

@@ -17,6 +17,14 @@
border-color: #d9d9d9;
}
.umb-node-preview--unpublished {
.umb-node-preview__icon,
.umb-node-preview__name,
.umb-node-preview__description {
opacity: 0.6;
}
}
.umb-node-preview__icon {
display: flex;
width: 25px;

View File

@@ -1,4 +1,4 @@
<div class="umb-node-preview" ng-class="{'umb-node-preview--sortable': sortable }">
<div class="umb-node-preview" ng-class="{'umb-node-preview--sortable': sortable, 'umb-node-preview--unpublished': published === false }">
<i ng-if="icon" class="umb-node-preview__icon {{ icon }}"></i>
<div class="umb-node-preview__content">
<div class="umb-node-preview__name">{{ name }}</div>

View File

@@ -194,8 +194,19 @@ function contentPickerController($scope, dialogService, entityResource, contentR
});
if (currIds.indexOf(item.id) < 0) {
item.icon = iconHelper.convertFromLegacyIcon(item.icon);
$scope.renderModel.push({ name: item.name, id: item.id, icon: item.icon, path: item.path });
// get url for content and media items
if(entityType !== "Member") {
entityResource.getUrl(item.id, entityType).then(function(data){
// update url
item.url = data.url;
// push item to render model
addSelectedItem(item);
});
} else {
addSelectedItem(item);
}
}
};
@@ -221,43 +232,28 @@ function contentPickerController($scope, dialogService, entityResource, contentR
//load current data
var modelIds = $scope.model.value ? $scope.model.value.split(',') : [];
var nodePromise = (entityType === "Document") ? contentResource.getByIds(modelIds) : entityResource.getByIds(modelIds, entityType);
var nodePromise = entityResource.getByIds(modelIds, entityType);
nodePromise.then(function (data) {
_.each(modelIds, function (id, i) {
var entity = _.find(data, function (d) {
return d.id == id;
});
if (entity) {
// set icon
if(entity.icon) {
entity.icon = iconHelper.convertFromLegacyIcon(entity.icon);
}
// set default icon
if (!entity.icon) {
switch (entityType) {
case "Document":
entity.icon = "icon-document";
break;
case "Media":
entity.icon = "icon-picture";
break;
case "Member":
entity.icon = "icon-user";
break;
}
}
var url = (entity.urls && entity.urls.length > 0) ? entity.urls[0] : "";
var path = ($scope.model.config.showPathOnHover) ? entity.path : "";
$scope.renderModel.push({ name: entity.name, id: entity.id, icon: entity.icon, path: path, url: url });
_.each(modelIds, function (id, i) {
var entity = _.find(data, function (d) {
return d.id == id;
});
if (entity) {
// get url for content and media items
if(entityType !== "Member") {
entityResource.getUrl(entity.id, entityType).then(function(data){
// update url
entity.url = data.url;
// push item to render model
addSelectedItem(entity);
});
} else {
addSelectedItem(entity);
}
}
});
@@ -266,6 +262,40 @@ function contentPickerController($scope, dialogService, entityResource, contentR
});
function addSelectedItem(item) {
// set icon
if(item.icon) {
item.icon = iconHelper.convertFromLegacyIcon(item.icon);
}
// set default icon
if (!item.icon) {
switch (entityType) {
case "Document":
item.icon = "icon-document";
break;
case "Media":
item.icon = "icon-picture";
break;
case "Member":
item.icon = "icon-user";
break;
}
}
$scope.renderModel.push({
"name": item.name,
"id": item.id,
"icon": item.icon,
"path": item.path,
"url": item.url,
"published": (item.metaData.IsPublished === false && entityType === "Document") ? false : true
// only content supports published/unpublished content so we set everything else to published so the UI looks correct
});
}
}
angular.module('umbraco').controller("Umbraco.PropertyEditors.ContentPickerController", contentPickerController);

View File

@@ -8,6 +8,7 @@
ng-repeat="node in renderModel"
icon="node.icon"
name="node.name"
published="node.published"
description="node.url"
sortable="sortable"
allow-remove="allowRemoveButton"

View File

@@ -144,6 +144,37 @@ namespace Umbraco.Web.Editors
return foundContent.Path.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
}
public dynamic GetUrl(int id, UmbracoEntityTypes type)
{
dynamic result = new System.Dynamic.ExpandoObject();
if(type == UmbracoEntityTypes.Document)
{
var foundUrl = Umbraco.Url(id);
if (string.IsNullOrEmpty(foundUrl) == false && foundUrl != "#")
{
result.url = foundUrl;
return result;
}
}
var ancestors = GetAncestors(id, type);
//if content, skip the first node for replicating NiceUrl defaults
if(type == UmbracoEntityTypes.Document) {
ancestors = ancestors.Skip(1);
}
result.url = "/" + string.Join("/", ancestors.Select(x => x.Name) );
return result;
}
/// <summary>
/// Gets an entity by it's unique id if the entity supports that
/// </summary>