Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic root with culture and segment #15287

Merged
merged 2 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/Umbraco.Web.BackOffice/Controllers/EntityController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Concurrent;

Check notice on line 1 in src/Umbraco.Web.BackOffice/Controllers/EntityController.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (v13/dev)

ℹ Getting worse: Lines of Code in a Single File

The lines of code increases from 1141 to 1145, improve code health by reducing it to 1000. The number of Lines of Code in a single file. More Lines of Code lowers the code health.

Check notice on line 1 in src/Umbraco.Web.BackOffice/Controllers/EntityController.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (v13/dev)

✅ Getting better: Primitive Obsession

The ratio of primitive types in function arguments decreases from 40.61% to 40.36%, threshold = 30.0%. The functions in this file have too many primitive types (e.g. int, double, float) in their function argument lists. Using many primitive types lead to the code smell Primitive Obsession. Avoid adding more primitive arguments.
using System.Dynamic;
using System.Globalization;
using System.IO;
Expand Down Expand Up @@ -69,6 +69,7 @@

private readonly AppCaches _appCaches;
private readonly IDynamicRootService _dynamicRootService;
private readonly IVariationContextAccessor _variationContextAccessor;
private readonly IBackOfficeSecurityAccessor _backofficeSecurityAccessor;
private readonly IContentService _contentService;
private readonly IContentTypeService _contentTypeService;
Expand Down Expand Up @@ -111,34 +112,36 @@
IUserService userService,
ILocalizationService localizationService,
AppCaches appCaches,
IDynamicRootService dynamicRootService)
IDynamicRootService dynamicRootService,
IVariationContextAccessor variationContextAccessor)
{
_treeService = treeService ?? throw new ArgumentNullException(nameof(treeService));
_treeSearcher = treeSearcher ?? throw new ArgumentNullException(nameof(treeSearcher));
_searchableTreeCollection = searchableTreeCollection ??
throw new ArgumentNullException(nameof(searchableTreeCollection));
_publishedContentQuery =
publishedContentQuery ?? throw new ArgumentNullException(nameof(publishedContentQuery));
_shortStringHelper = shortStringHelper ?? throw new ArgumentNullException(nameof(shortStringHelper));
_entityService = entityService ?? throw new ArgumentNullException(nameof(entityService));
_backofficeSecurityAccessor = backofficeSecurityAccessor ??
throw new ArgumentNullException(nameof(backofficeSecurityAccessor));
_publishedUrlProvider =
publishedUrlProvider ?? throw new ArgumentNullException(nameof(publishedUrlProvider));
_contentService = contentService ?? throw new ArgumentNullException(nameof(contentService));
_umbracoMapper = umbracoMapper ?? throw new ArgumentNullException(nameof(umbracoMapper));
_dataTypeService = dataTypeService ?? throw new ArgumentNullException(nameof(dataTypeService));
_sqlContext = sqlContext ?? throw new ArgumentNullException(nameof(sqlContext));
_localizedTextService =
localizedTextService ?? throw new ArgumentNullException(nameof(localizedTextService));
_fileService = fileService ?? throw new ArgumentNullException(nameof(fileService));
_contentTypeService = contentTypeService ?? throw new ArgumentNullException(nameof(contentTypeService));
_mediaTypeService = mediaTypeService ?? throw new ArgumentNullException(nameof(mediaTypeService));
_macroService = macroService ?? throw new ArgumentNullException(nameof(macroService));
_userService = userService ?? throw new ArgumentNullException(nameof(userService));
_localizationService = localizationService ?? throw new ArgumentNullException(nameof(localizationService));
_appCaches = appCaches ?? throw new ArgumentNullException(nameof(appCaches));
_dynamicRootService = dynamicRootService;
_variationContextAccessor = variationContextAccessor;

Check notice on line 144 in src/Umbraco.Web.BackOffice/Controllers/EntityController.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (v13/dev)

ℹ Getting worse: Constructor Over-Injection

EntityController increases from 21 to 22 arguments, threshold = 5. This constructor has too many arguments, indicating an object with low cohesion or missing function argument abstraction. Avoid adding more arguments.
}

[Obsolete("Use non-obsolete ctor. This will be removed in Umbraco 14.")]
Expand Down Expand Up @@ -183,7 +186,8 @@
userService,
localizationService,
appCaches,
StaticServiceProvider.Instance.GetRequiredService<IDynamicRootService>())
StaticServiceProvider.Instance.GetRequiredService<IDynamicRootService>(),
StaticServiceProvider.Instance.GetRequiredService<IVariationContextAccessor>())
{

}
Expand Down Expand Up @@ -587,6 +591,8 @@
public DynamicRoot Query { get; set; } = null!;

public int CurrentId { get; set; }
public string? CurrentCulture { get; set; }
public string? CurrentSegment { get; set; }

public int ParentId { get; set; }
}
Expand Down Expand Up @@ -617,6 +623,8 @@
AnyOfDocTypeKeys = x.AnyOfDocTypeKeys
})
};

_variationContextAccessor.VariationContext = new VariationContext(model.CurrentCulture, model.CurrentSegment);
var startNodes = (await _dynamicRootService.GetDynamicRootsAsync(startNodeSelector)).ToArray();

Guid? first = startNodes.Any() ? startNodes.First() : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ function entityResource($q, $http, umbRequestHelper) {
'Failed to retrieve entity data for query ' + query);
},

getDynamicRoot: function (query, currentId, parentId) {
getDynamicRoot: function (query, currentId, parentId, culture, segment) {
return umbRequestHelper.resourcePromise(
$http.post(
umbRequestHelper.getApiUrl(
Expand All @@ -375,7 +375,9 @@ function entityResource($q, $http, umbRequestHelper) {
{
query: JSON.parse(query),
parentId: parentId,
currentId: currentId
currentId: currentId,
currentCulture: culture,
currentSegment: segment
}),
'Failed to retrieve entity data for query ' + query);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,13 @@ function contentPickerController($scope, $q, $routeParams, $location, entityReso
});
}
else if ($scope.model.config.startNode.dynamicRoot) {

entityResource.getDynamicRoot(
JSON.stringify($scope.model.config.startNode.dynamicRoot),
editorState.current.id,
editorState.current.parentId,
"Document"
$scope.model.culture,
$scope.model.segment
).then(function (ent) {
if(ent) {
dialogOptions.startNodeId = ($scope.model.config.idType === "udi" ? ent.udi : ent.id).toString();
Expand Down
Loading