Allows configurable segments to be advertised as variants
This commit is contained in:
+21
-12
@@ -1,5 +1,14 @@
|
||||
function segmentDashboardController($scope, umbRequestHelper, $log, $http, formHelper) {
|
||||
|
||||
function refreshData() {
|
||||
return umbRequestHelper.resourcePromise(
|
||||
$http.get(umbRequestHelper.getApiUrl("segmentDashboardApiBaseUrl", "GetProviders")),
|
||||
"Failed to retrieve provider data")
|
||||
.then(function(data) {
|
||||
$scope.providers = data;
|
||||
});
|
||||
}
|
||||
|
||||
$scope.providers = [];
|
||||
$scope.configuringSegments = false;
|
||||
$scope.providerConfig = {
|
||||
@@ -74,8 +83,11 @@ function segmentDashboardController($scope, umbRequestHelper, $log, $http, formH
|
||||
var provider = _.find($scope.providers, function (i) { return i.typeName === $scope.providerConfig.providerTypeName; });
|
||||
provider.segmentConfig = $scope.segmentConfig;
|
||||
|
||||
//exit editing config
|
||||
$scope.cancel();
|
||||
refreshData().then(function() {
|
||||
//exit editing config
|
||||
$scope.cancel();
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -94,17 +106,14 @@ function segmentDashboardController($scope, umbRequestHelper, $log, $http, formH
|
||||
var provider = _.find($scope.providers, function (i) { return i.typeName === $scope.providerConfig.providerTypeName; });
|
||||
provider.variantConfig = $scope.variantConfig;
|
||||
|
||||
//exit editing config
|
||||
$scope.cancel();
|
||||
refreshData().then(function () {
|
||||
//exit editing config
|
||||
$scope.cancel();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
umbRequestHelper.resourcePromise(
|
||||
$http.get(umbRequestHelper.getApiUrl("segmentDashboardApiBaseUrl", "GetProviders")),
|
||||
"Failed to retrieve provider data")
|
||||
.then(function(data) {
|
||||
$scope.providers = data;
|
||||
});
|
||||
|
||||
|
||||
//initial data load
|
||||
refreshData();
|
||||
}
|
||||
angular.module("umbraco").controller("Umbraco.Dashboard.SegmentDashboard", segmentDashboardController);
|
||||
@@ -81,8 +81,12 @@
|
||||
<span class="help-inline" val-msg-for="value" val-toggle-msg="required">Required</span>
|
||||
</umb-control-group>
|
||||
|
||||
<umb-control-group label="Persist segment" alias="value" description="">
|
||||
<input type="checkbox" name="persist" ng-model="$parent.item.persist" title="This might be useful if you want to track an assigned segment. For example, if it's a referral provider a segment might be set when coming from 'mysite.com' and you want to know about that later on when the segment no longer exists in the request." />
|
||||
<umb-control-group label="Persist segment" alias="value" description="This might be useful if you want to track an assigned segment">
|
||||
<input type="checkbox" name="persist" ng-model="$parent.item.persist" title=" For example, if it's a referral provider a segment might be set when coming from 'mysite.com' and you want to know about that later on when the segment no longer exists in the request." />
|
||||
</umb-control-group>
|
||||
|
||||
<umb-control-group label="Use as a Content Variant" alias="value" description="If checked, this segment key can be used to create custom Content Variants">
|
||||
<input type="checkbox" name="persist" ng-model="$parent.item.asVariant" />
|
||||
</umb-control-group>
|
||||
|
||||
</ng-form>
|
||||
|
||||
@@ -50,7 +50,8 @@ namespace Umbraco.Web.Editors
|
||||
{
|
||||
name = vari.VariantName,
|
||||
key = vari.SegmentMatchKey,
|
||||
enabled = x.variantConfig.ContainsKey(vari.SegmentMatchKey) && x.variantConfig[vari.SegmentMatchKey]
|
||||
enabled = x.variantConfig.ContainsKey(vari.SegmentMatchKey) && x.variantConfig[vari.SegmentMatchKey],
|
||||
asVariant = x.variantConfig.ContainsKey(vari.SegmentMatchKey) && x.variantConfig[vari.SegmentMatchKey]
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
@@ -35,5 +35,11 @@ namespace Umbraco.Web.Models.Segments
|
||||
/// </remarks>
|
||||
[DataMember(Name = "persist")]
|
||||
public bool Persist { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A flag to determine if this segment is allowed to be a variant (advertised)
|
||||
/// </summary>
|
||||
[DataMember(Name = "asVariant")]
|
||||
public bool AllowedAsVariant { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -23,13 +23,26 @@ namespace Umbraco.Web.Routing.Segments
|
||||
/// which would normally be a regex statement, if it matches the returned value then we will apply the configured key/value as a segment
|
||||
/// in the request.
|
||||
///
|
||||
/// TODO: We need to decide if configurable segment provider can advertise segments to be used in variations - but I don't think so since they
|
||||
/// can be added/removed by users
|
||||
/// </remarks>
|
||||
public abstract class ConfigurableSegmentProvider : ContentSegmentProvider
|
||||
{
|
||||
private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim();
|
||||
|
||||
/// <summary>
|
||||
/// Override to return the statically assigned variants for this provider as well as any segments
|
||||
/// that are configured to be variants.
|
||||
/// </summary>
|
||||
public override IEnumerable<ContentVariantAttribute> AssignableContentVariants
|
||||
{
|
||||
get
|
||||
{
|
||||
return base.AssignableContentVariants.Union(
|
||||
ReadSegmentConfiguration()
|
||||
.Where(x => x.AllowedAsVariant)
|
||||
.Select(x => new ContentVariantAttribute(x.Key, x.Key, x.Value)));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current provider's value (i.e. if the provider was a referal provider, this would return the current referrer)
|
||||
/// </summary>
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace Umbraco.Web.Routing.Segments
|
||||
/// <summary>
|
||||
/// Returns the Content Variants that this provider supports
|
||||
/// </summary>
|
||||
public IEnumerable<ContentVariantAttribute> AssignableContentVariants
|
||||
public virtual IEnumerable<ContentVariantAttribute> AssignableContentVariants
|
||||
{
|
||||
get { return GetType().GetCustomAttributes<ContentVariantAttribute>(false).ToArray(); }
|
||||
}
|
||||
|
||||
@@ -40,7 +40,8 @@ namespace Umbraco.Web.Routing.Segments
|
||||
|
||||
public IEnumerable<ContentVariantAttribute> GetAssignableVariants(IDictionary<string, bool> segmentProviderStatus)
|
||||
{
|
||||
//These are the assignable variants based on the installed providers (statically advertised variants)
|
||||
//These are the assignable variants based on the installed providers (statically advertised variants) or
|
||||
// configured segments that have been flagged as variants
|
||||
// that are enabled via the back office. If they are not enabled, they will not show up.
|
||||
|
||||
var assignableSegments = this.Providers
|
||||
@@ -55,7 +56,8 @@ namespace Umbraco.Web.Routing.Segments
|
||||
.Select(vari => vari.Key).ToArray() // get the key
|
||||
})
|
||||
//only allow the onces that are enabled
|
||||
.SelectMany(x => x.instance.AssignableContentVariants.Where(vari => x.enabledVariants.Contains(vari.SegmentMatchKey)));
|
||||
.SelectMany(x =>
|
||||
x.instance.AssignableContentVariants.Where(vari => x.enabledVariants.Contains(vari.SegmentMatchKey)));
|
||||
|
||||
return assignableSegments;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user