Fixes up nullable State, fixes up tracking global query strings in case they are removed by other routes

This commit is contained in:
Shannon
2018-09-14 11:31:43 +10:00
parent 8c90b7fa28
commit ec71814ec2
11 changed files with 73 additions and 38 deletions

View File

@@ -204,6 +204,29 @@ function navigationService($rootScope, $route, $routeParams, $log, $location, $q
});
},
/**
* @ngdoc method
* @name umbraco.services.navigationService#retainQueryStrings
* @methodOf umbraco.services.navigationService
*
* @description
* Will check the next route parameters to see if any of the query strings that should be retained from the previous route are missing,
* if they are they will be merged and an object containing all route parameters is returned. If nothing should be changed, then null is returned.
* @param {Object} currRouteParams The current route parameters
* @param {Object} nextRouteParams The next route parameters
*/
retainQueryStrings: function (currRouteParams, nextRouteParams) {
var toRetain = angular.copy(nextRouteParams);
var updated = false;
_.each(retainedQueryStrings, function (r) {
if (currRouteParams[r] && !nextRouteParams[r]) {
toRetain[r] = currRouteParams[r];
updated = true;
}
});
return updated ? toRetain : null;
},
/**
* @ngdoc method
* @name umbraco.services.navigationService#load

View File

@@ -122,12 +122,25 @@ app.run(['userService', '$q', '$log', '$rootScope', '$route', '$location', 'urlH
$route.reload();
}
else {
//check if the location being changed is only the mculture query string, if so, cancel the routing since this is just
//used as a global persistent query string that does not change routes.
//check if the location being changed is only due to global/state query strings which means the location change
//isn't actually going to cause a route change.
if (navigationService.isRouteChangingNavigation(currentRouteParams, next.params)) {
//continue the route
$route.reload();
//The location change will cause a route change. We need to ensure that the global/state
//query strings have not been stripped out. If they have, we'll re-add them and re-route.
var toRetain = navigationService.retainQueryStrings(currentRouteParams, next.params);
if (toRetain) {
$route.updateParams(toRetain);
}
else {
//continue the route
$route.reload();
}
}
else {
//navigation is not changing but we should update the currentRouteParams to include all current parameters
currentRouteParams = angular.copy(next.params);
}
}
});

View File

@@ -15,7 +15,7 @@
{{ item.name }}
</div>
<ul class="umb-content-grid__details-list" ng-class="{'-light': !item.published&& item.updater != null}">
<ul class="umb-content-grid__details-list" ng-class="{'-light': !item.published && item.updater != null}">
<li class="umb-content-grid__details-item" ng-if="item.state">
<div class="umb-content-grid__details-label"><localize key="general_status"></localize>:</div>
<div class="umb-content-grid__details-value"><umb-variant-state variant="item"></umb-variant-state></div>
@@ -36,4 +36,4 @@
<localize key="content_noItemsToShow">There are no items to show</localize>
</umb-empty-state>
</div>
</div>

View File

@@ -20,6 +20,9 @@ namespace Umbraco.Web.Models.ContentEditing
[DataMember(Name = "createDate")]
public DateTime CreateDate { get; set; }
/// <summary>
/// Boolean indicating if this item is published or not based on it's <see cref="State"/>
/// </summary>
[DataMember(Name = "published")]
public bool Published => State == ContentSavedState.Published || State == ContentSavedState.PublishedPendingChanges;
@@ -42,9 +45,15 @@ namespace Umbraco.Web.Models.ContentEditing
[DataMember(Name = "sortOrder")]
public int SortOrder { get; set; }
/// <summary>
/// The saved/published state of an item
/// </summary>
/// <remarks>
/// This is nullable since it's only relevant for content (non-content like media + members will be null)
/// </remarks>
[DataMember(Name = "state")]
[JsonConverter(typeof(StringEnumConverter))]
public ContentSavedState State { get; set; }
public ContentSavedState? State { get; set; }
protected bool Equals(ContentItemBasic other)
{

View File

@@ -5,11 +5,6 @@
/// </summary>
public enum ContentSavedState
{
/// <summary>
/// The state has not been set
/// </summary>
NotSet = -1,
/// <summary>
/// The item isn't created yet
/// </summary>

View File

@@ -82,7 +82,7 @@ namespace Umbraco.Web.Models.Mapping
.ForMember(dest => dest.AdditionalData, opt => opt.Ignore())
.ForMember(dest => dest.UpdateDate, opt => opt.ResolveUsing<UpdateDateResolver>())
.ForMember(dest => dest.Name, opt => opt.ResolveUsing<NameResolver>())
.ForMember(dest => dest.State, opt => opt.ResolveUsing<ContentSavedStateResolver<ContentPropertyBasic>>());
.ForMember(dest => dest.State, opt => opt.ResolveUsing<ContentBasicSavedStateResolver<ContentPropertyBasic>>());
//FROM IContent TO ContentPropertyCollectionDto
//NOTE: the property mapping for cultures relies on a culture being set in the mapping context

View File

@@ -7,6 +7,21 @@ using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Mapping
{
/// <summary>
/// Returns the <see cref="ContentSavedState?"/> for an <see cref="IContent"/> item
/// </summary>
/// <typeparam name="T"></typeparam>
internal class ContentBasicSavedStateResolver<T> : IValueResolver<IContent, IContentProperties<T>, ContentSavedState?>
where T : ContentPropertyBasic
{
private readonly ContentSavedStateResolver<T> _inner = new ContentSavedStateResolver<T>();
public ContentSavedState? Resolve(IContent source, IContentProperties<T> destination, ContentSavedState? destMember, ResolutionContext context)
{
return _inner.Resolve(source, destination, default, context);
}
}
/// <summary>
/// Returns the <see cref="ContentSavedState"/> for an <see cref="IContent"/> item
/// </summary>

View File

@@ -44,7 +44,7 @@ namespace Umbraco.Web.Models.Mapping
.ForMember(dest => dest.TreeNodeUrl, opt => opt.ResolveUsing(contentTreeNodeUrlResolver))
.ForMember(dest => dest.Notifications, opt => opt.Ignore())
.ForMember(dest => dest.Errors, opt => opt.Ignore())
.ForMember(dest => dest.State, opt => opt.ResolveUsing<SavedStateResolver<ContentPropertyDisplay>>())
.ForMember(dest => dest.State, opt => opt.UseValue<ContentSavedState?>(null))
.ForMember(dest => dest.Edited, opt => opt.Ignore())
.ForMember(dest => dest.Updater, opt => opt.Ignore())
.ForMember(dest => dest.Alias, opt => opt.Ignore())
@@ -62,7 +62,7 @@ namespace Umbraco.Web.Models.Mapping
.ForMember(dest => dest.Icon, opt => opt.MapFrom(src => src.ContentType.Icon))
.ForMember(dest => dest.Trashed, opt => opt.MapFrom(src => src.Trashed))
.ForMember(dest => dest.ContentTypeAlias, opt => opt.MapFrom(src => src.ContentType.Alias))
.ForMember(dest => dest.State, opt => opt.ResolveUsing<SavedStateResolver<ContentPropertyBasic>>())
.ForMember(dest => dest.State, opt => opt.UseValue<ContentSavedState?>(null))
.ForMember(dest => dest.Edited, opt => opt.Ignore())
.ForMember(dest => dest.Updater, opt => opt.Ignore())
.ForMember(dest => dest.Alias, opt => opt.Ignore())

View File

@@ -73,7 +73,7 @@ namespace Umbraco.Web.Models.Mapping
.ForMember(dest => dest.MembershipScenario, opt => opt.ResolveUsing(src => membershipScenarioMappingResolver.Resolve(src)))
.ForMember(dest => dest.Notifications, opt => opt.Ignore())
.ForMember(dest => dest.Errors, opt => opt.Ignore())
.ForMember(dest => dest.State, opt => opt.ResolveUsing<SavedStateResolver<ContentPropertyDisplay>>())
.ForMember(dest => dest.State, opt => opt.UseValue<ContentSavedState?>(null))
.ForMember(dest => dest.Edited, opt => opt.Ignore())
.ForMember(dest => dest.Updater, opt => opt.Ignore())
.ForMember(dest => dest.Alias, opt => opt.Ignore())
@@ -91,7 +91,7 @@ namespace Umbraco.Web.Models.Mapping
.ForMember(dest => dest.Email, opt => opt.MapFrom(src => src.Email))
.ForMember(dest => dest.Username, opt => opt.MapFrom(src => src.Username))
.ForMember(dest => dest.Trashed, opt => opt.Ignore())
.ForMember(dest => dest.State, opt => opt.ResolveUsing<SavedStateResolver<ContentPropertyBasic>>())
.ForMember(dest => dest.State, opt => opt.UseValue<ContentSavedState?>(null))
.ForMember(dest => dest.Edited, opt => opt.Ignore())
.ForMember(dest => dest.Updater, opt => opt.Ignore())
.ForMember(dest => dest.Alias, opt => opt.Ignore())

View File

@@ -1,19 +0,0 @@
using AutoMapper;
using Umbraco.Core.Models;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Mapping
{
/// <summary>
/// Returns the <see cref="ContentSavedState"/> for an <see cref="IContentBase"/> item
/// </summary>
/// <typeparam name="T"></typeparam>
internal class SavedStateResolver<T> : IValueResolver<IContentBase, IContentProperties<T>, ContentSavedState>
where T : ContentPropertyBasic
{
public ContentSavedState Resolve(IContentBase source, IContentProperties<T> destination, ContentSavedState destMember, ResolutionContext context)
{
return source.Id == 0 ? ContentSavedState.NotCreated : ContentSavedState.Draft;
}
}
}

View File

@@ -142,7 +142,6 @@
<Compile Include="Media\Exif\Utility.cs" />
<Compile Include="Media\ImageHelper.cs" />
<Compile Include="Media\UploadAutoFillProperties.cs" />
<Compile Include="Models\Mapping\SavedStateResolver.cs" />
<Compile Include="Security\ActiveDirectoryBackOfficeUserPasswordChecker.cs" />
<Compile Include="Security\BackOfficeClaimsIdentityFactory.cs" />
<Compile Include="Security\BackOfficeUserManagerMarker.cs" />