Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sentient 10 posts 60 karma points
    Aug 09, 2015 @ 22:41
    Sentient
    0

    Sort order problems with inherited document type properties

    The properties for parent doc types are showing below those for inheriting child doctypes even though the sort order indicates they would be in the reverse direction. E.G.

    Base doc type has two properties h1 SortOrder 10, h2 SortOrder 11 Child doc type has properties b1 SortOrder 20, b2 SortOrder 30

    The displayed order on a node created as a child type is however b1, b2, h1, h2 and it completely ignores the sort order (sometimes it would be b2, b1, h2, h1).

    In the simple case above you would have the primary properties with a lower sort index placed below the child properties. Given a case where the child doc type can have 20 properties per tab this can cause issues as the primary properties with the lower sort index should be shown first.

    Current Umbraco version 7.2.8 Installed Umbraco verison 7.2.5 Updated through nuget package manager in Visual studio Cache and indexes refreshed multiple times. Occurs on some environments not on others even though the db is backed up and kept in sync.
    Note the sort order has never been amended through the db those orders above would be the sort order when the property was created i.e. 10, 11, 20, 30 etc.

    As a client has already contented most of the site recreating the doctypes from scratch is unavailable and since the sort orders and tabs are correct in the db that option would provide little change. This appears to be a controller view issue which is ignoring the provided sort order provided in the db and instead using something else to sort properties.

    An earlier occurrence of this issue has the admin reinstall the doctypes/content from scratch but the UI should be able to use the provided sort order i.e. the one created and stored in the db and retrieved in the property info.

    https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/56037-Sort-order-problems-with-inherited-document-type-properties

  • Sentient 10 posts 60 karma points
    Aug 24, 2015 @ 05:05
    Sentient
    100

    Further to this found where an issue originates in the /umbraco/Views/content/edit.html the line:

    <umb-property property="property" ng-repeat="property in tab.properties">
    

    doesn't have the properties in sorted order first. In fact when the property data is loaded the sort order for properties is ignored completely hence the properties will not load in the provided order but rather an arbitrary order will no opportunity to correct it in the controller Umbraco.Editors.Content.EditController. This is quite disturbing as I cannot find an angular resource which can provide the property type data to correct & sort the loaded properties by the sort order. Please can anyone suggest one? I am leaning towards an ugly custom edit to fix this. Ugly in that it would not be future proof for later Umbraco versions and would need to be stored outside & override the Umbraco edit view. That ugly.

    Essentially the workaround would create a new custom UmbracoAuthorizedJsonController with the methods:

    public List<PropertyType> GetPropertyTypesForNode(String id)
          {
    
              var helper = new UmbracoHelper(UmbracoContext.Current);
              var list = new List<PropertyType>();
              var result = 0;
              if (!String.IsNullOrWhiteSpace(id) && Int32.TryParse(id,out result))
              {
                  var content = helper.TypedContent(result);
                  if (content != null)
                  {
                      list.AddRange(GetContentTypePropertyTypes(content.DocumentTypeId));
                  }
    
              }
    
              return list;
          }
    
          private List<PropertyType> GetContentTypePropertyTypes(int id)
          {
    
              var list = new List<PropertyType>();
              var doctype = UmbracoContext.Application.Services.ContentTypeService.GetContentType(id);
              if (doctype != null)
              {
                  list = doctype.PropertyTypes.ToList();
                  if (doctype.ParentId != 0)
                  {
                      list.AddRange(GetContentTypePropertyTypes(doctype.ParentId));
                  }
              }
    
              return list;
          } 
    

    Then create a new plugin manifest which will include: 1. a resource to call the controller methods

    angular.module("umbraco.resources").factory("propertyTypeResource", function ($q, $http) {
        return {
            getPropertyTypesForNode: function (id) {
               return $http.get("Backoffice/ApiExtensions/DocumentPropertyTypes/GetPropertyTypesForNode?id=" + id);
            },
        };
    
    });
    

    and 2. a copy of the Umbraco.Editors.Content.EditController renamed with an additional code block added to the end of the init(content) function:

    propertyTypeResource.getPropertyTypesForNode($scope.content.id).then(function(response) {
                _.each(response.data, function(e, i) {
                    _.each($scope.content.tabs, function(tab, j) {
                        _.each(tab.properties, function(prop, k) {
                            if (prop != undefined && prop.alias != undefined && e !=undefined && e.Alias!=undefined && prop.alias==e.Alias) {
                                prop.sortOrder = e.SortOrder;
                            }
                        });
                    });
                });
            }, function (error) { });
    

    Then change the edit.html to use the new copied controller instead and add a orderby clause to the ng-repeat of properties:

    <umb-property property="property" ng-repeat="property in tab.properties | orderBy:'+sortOrder'">
    

    Now the ng-repeat will order the properties by the sortOrder they had been provided in the doctype definition (stored in db) and will correctly sort parent child properties. However this would be a specific change across the edit.html and will need to be checked/perhaps reedited when updating Umbraco (hence not future proof).

  • Zakhar 171 posts 397 karma points
    Feb 22, 2016 @ 16:15
    Zakhar
    0

    Thanks for the solution Sentient!

    This seem to be a hardcore fix though, might be lost or stop working after an upgrade. Is this going to be fixed in core?

    Can anyone from HQ comment?

    Thanks!

  • Jose Marcenaro 11 posts 112 karma points c-trib
    Oct 24, 2016 @ 20:44
    Jose Marcenaro
    0

    Thanks Sentient for your creative solution. I have the same problem in a slightly different context (Doc Type Grid Editor) so I implemented your idea in that plugin code and submitted a Pull Request.

    https://github.com/umco/umbraco-doc-type-grid-editor/pull/55

    You are mentioned in the credit for the PR.

  • bhagirath pancholi 19 posts 88 karma points
    Mar 09, 2018 @ 13:14
    bhagirath pancholi
    0

    in seo control i put high number(200) so. whenever you composite seo control in pages. seo control will appear right most side(second last).

    i set generic propety control to 201.by that whenever you composite this control. this will appear last. see imageenter image description here

Please Sign in or register to post replies

Write your reply to:

Draft