Ejemplo n.º 1
0
        public ActionResult GetSingleNode(DefinitionPathInfo defInfo)
        {
            var content = (Content)XamlConfigurationParser.CreateFrom(defInfo.Xml);

            var objFromDef = _definitionEditorService.GetObjectFromPath(content, defInfo.Path, out var notFoundInDef);

            if (objFromDef == null)
            {
                return(Json(new { MissingFieldToDeleteId = defInfo.Path }));
            }

            DefinitionTreeNode resultObj = null;

            switch (objFromDef)
            {
            case Content def:
            {
                var isFromDictionaries = _definitionEditorService.GetParentObjectFromPath(content, defInfo.Path) is Dictionaries;

                resultObj = new DefinitionTreeNode(def, null, defInfo.Path, isFromDictionaries, notFoundInDef, _contentService);
                break;
            }

            case Field field:
            {
                var existsInQp = true;

                if (!(field is BaseVirtualField))
                {
                    existsInQp = _fieldService.Read(field.FieldId) != null;
                }

                resultObj = new DefinitionTreeNode(field, null, defInfo.Path, !existsInQp, notFoundInDef);
                break;
            }
            }

            return(new ContentResult()
            {
                ContentType = "application/json", Content = JsonConvert.SerializeObject(resultObj)
            });
        }
Ejemplo n.º 2
0
        public static DefinitionTreeNode[] GetObjectsFromPath(Content rootContent, string path, IFieldService fieldService, DefinitionEditorService definitionEditorService, ContentService contentService)
        {
            //запрос корня
            if (string.IsNullOrEmpty(path))
            {
                return new[] { new DefinitionTreeNode(rootContent, string.Empty, null, false, false, contentService) }
            }
            ;

            bool notFoundInDef;

            object foundObject = definitionEditorService.GetObjectFromPath(rootContent, path, out notFoundInDef);

            if (foundObject is Content)
            {
                return(GetContentFields((Content)foundObject, fieldService, path, foundObject == rootContent));
            }

            var contentsFromDef = definitionEditorService.GetContentsFromField((Field)foundObject);

            var nodesFromContentsInDef = contentsFromDef
                                         .Select(x => new DefinitionTreeNode(x, path, null, foundObject is Dictionaries, false, contentService))
                                         .ToArray();

            if (foundObject is ExtensionField)
            {
                var allExtensions = fieldService.ListRelated(fieldService.Read(((Field)foundObject).FieldId).ContentId)
                                    .Where(x => x.Aggregated)
                                    .Select(x => x.Content)
                                    .ToArray();

                return(nodesFromContentsInDef
                       .Concat(allExtensions
                               .Where(x => contentsFromDef.All(y => y.ContentId != x.Id))
                               .Select(x => new DefinitionTreeNode(x, path)))
                       .ToArray());
            }
            else if (foundObject is Dictionaries)
            {
                int[] allContentIds = definitionEditorService.GetAllContentIdsFromTree(rootContent);

                return(nodesFromContentsInDef
                       .Concat(allContentIds
                               .Where(x => contentsFromDef.All(y => y.ContentId != x))
                               .Select(x => new DefinitionTreeNode(contentService.Read(x), path))
                               .OrderBy(x => x.text))
                       .ToArray());
            }
            else
            {
                return(nodesFromContentsInDef);
            }
        }
    }