Exemple #1
0
        public ActionResult _RelateableFields(int?contentId, int?fieldId)
        {
            if (contentId == null)
            {
                return(Json(new
                {
                    success = true
                }));
            }

            if (contentId == 0 && fieldId.HasValue)
            {
                contentId = FieldService.Read(fieldId.Value).ContentId;
            }

            var content = ContentService.Read(contentId.Value);

            if (content == null)
            {
                throw new ArgumentException(string.Format(ContentStrings.ContentNotFound, contentId.Value));
            }

            Func <Field, bool> fieldFilter = f => true;

            if (fieldId.HasValue)
            {
                fieldFilter = f => !f.IsNew && f.Id != fieldId.Value;
            }

            return(Json(new
            {
                success = true,
                data = content.RelateableFields.Where(fieldFilter).Select(f => new { id = f.Id, text = f.Name })
            }));
        }
        public JsonResult LoadVeConfig(int fieldId, int siteId)
        {
            var result = new JSendResponse {
                Status = JSendStatus.Success
            };

            VisualEditorStyleVm StyleMapFn(VisualEditorStyle entry) => new VisualEditorStyleVm
            {
                Name       = entry.Name,
                Element    = entry.Tag,
                Overrides  = entry.OverridesTag,
                Styles     = entry.StylesItems.Any() ? entry.StylesItems.ToDictionary(k => k.Name.Replace(' ', '_'), v => v.ItemValue) : null,
                Attributes = entry.AttributeItems.Any() ? entry.AttributeItems.ToDictionary(k => k.Name, v => v.ItemValue) : null
            };

            VisualEditorPluginVm PluginMapFn(VisualEditorPlugin entry) => new VisualEditorPluginVm
            {
                Name = entry.Name,
                Url  = entry.Url
            };

            var veCommands     = FieldService.GetResultVisualEditorCommands(fieldId, siteId).Where(n => n.On).ToList();
            var includedStyles = FieldService.GetResultStyles(fieldId, siteId).Where(ves => ves.On).OrderBy(ves => ves.Order).ToList();
            var model          = new VisualEditorConfigVm
            {
                StylesSet    = includedStyles.Where(ves => !ves.IsFormat).Select(StyleMapFn),
                FormatsSet   = includedStyles.Where(ves => ves.IsFormat).Select(StyleMapFn).EmptyIfNull(),
                ExtraPlugins = VisualEditorHelpers.GetVisualEditorPlugins(veCommands).Select(PluginMapFn).EmptyIfNull(),
                Toolbar      = VisualEditorHelpers.GenerateToolbar(veCommands)
            };

            if (fieldId != 0)
            {
                var field = FieldService.Read(fieldId);
                model.Language            = field.VisualEditor.Language;
                model.DocType             = field.VisualEditor.DocType;
                model.FullPage            = field.VisualEditor.FullPage;
                model.EnterMode           = field.VisualEditor.EnterMode;
                model.ShiftEnterMode      = field.VisualEditor.ShiftEnterMode;
                model.UseEnglishQuotes    = field.VisualEditor.UseEnglishQuotes;
                model.DisableListAutoWrap = field.VisualEditor.DisableListAutoWrap;
                model.Height      = field.VisualEditor.Height;
                model.BodyClass   = field.RootElementClass;
                model.ContentsCss = field.ExternalCssItems.Select(css => css.Url);
            }

            try
            {
                result.Data = model;
            }
            catch (Exception)
            {
                result.Status  = JSendStatus.Error;
                result.Message = "Непредвиденная ошибка на сервере";
            }

            return(JsonCamelCase(result));
        }
        public async Task <ActionResult> StringEnum(string elementIdPrefix, [FromQuery(Name = "fieldID")] int fieldId)
        {
            ViewBag.QueryDropDownListID = elementIdPrefix + "_queryDropDownList";
            ViewBag.IsNullCheckBoxID    = elementIdPrefix + "_isNullCheckBox";
            var model = FieldService.Read(fieldId).StringEnumItems.Select(o => new QPSelectListItem {
                Value = o.Value, Text = o.Alias
            }).ToList();

            return(await JsonHtml("StringEnum", model));
        }
Exemple #4
0
        public ActionResult Properties(string tabId, int parentId, int id, string successfulActionCode, bool?orderChanged, bool?viewInListAffected)
        {
            var content = FieldService.Read(id);
            var model   = FieldViewModel.Create(content, tabId, parentId);

            model.SuccesfulActionCode = successfulActionCode;
            model.OrderChanged        = orderChanged ?? false;
            model.ViewInListAffected  = viewInListAffected ?? false;
            return(JsonHtml("Properties", model));
        }
        public ActionResult StringEnum(string elementIdPrefix, int fieldID)
        {
            ViewBag.QueryDropDownListID = elementIdPrefix + "_queryDropDownList";
            ViewBag.IsNullCheckBoxID    = elementIdPrefix + "_isNullCheckBox";
            var model = FieldService.Read(fieldID).StringEnumItems.Select(o => new QPSelectListItem {
                Value = o.Value, Text = o.Alias
            }).ToList();

            return(JsonHtml("StringEnum", model));
        }
        public async Task <ActionResult> ContentsListForClassifier(string elementIdPrefix, [FromQuery(Name = "fieldID")] int fieldId)
        {
            var classifier = FieldService.Read(fieldId);

            ViewBag.ElementIdPrefix         = elementIdPrefix;
            ViewBag.ContentElementID        = string.Format("{0}_contentID", ViewBag.ElementIdPrefix);
            ViewBag.IsNullCheckBoxElementID = string.Format("{0}_isNullCheckBox", ViewBag.ElementIdPrefix);
            IEnumerable <QPSelectListItem> model = FieldService.GetAggregetableContentsForClassifier(classifier).Select(o => new QPSelectListItem {
                Value = o.Value, Text = o.Text
            }).ToList();

            return(await JsonHtml("ContentsListForClassifier", model));
        }
Exemple #7
0
        /// <exception cref="InvalidOperationException"/>
        public ArticleObject[] PreloadRelationArticles(
            EntityField entityField, HashSet <Article> visited, Dictionaries dictionaries = null)
        {
            if (entityField == null)
            {
                throw new ArgumentNullException(nameof(entityField));
            }
            if (visited == null)
            {
                throw new ArgumentNullException(nameof(visited));
            }

            QP8BLL.Field qpField = _fieldService.Read(entityField.FieldId);

            string relationCondition = GetRelationCondition(entityField, qpField);

            return(PreloadRelationArticles(entityField, relationCondition, visited, dictionaries));
        }
        private List <FieldValue> GetBackwardFieldValues(Article article, IEnumerable <BackwardRelationField> fields, bool excludeArchive)
        {
            var fieldValues = new List <FieldValue>();

            foreach (var field in fields)
            {
                var articleField = FieldService.Read(field.FieldId);
                var value        = GetBackwardValue(articleField, article.Id, excludeArchive);

                var fv = new FieldValue();
                fv.Article = article;
                fv.Field   = articleField;
                fv.UpdateValue(value);

                fieldValues.Add(fv);
            }

            return(fieldValues);
        }
        /// <summary>
        /// Рекурсивно обходит <see cref="Content"/>, генерирует корневую схему и заполняет
        /// <see cref="SchemaContext.SchemasByContent"/> - созданные схемы контентов
        /// и <see cref="SchemaContext.RepeatedContents"/> - повторяющиеся контенты
        /// </summary>
        /// <exception cref="NotSupportedException" />
        /// <exception cref="InvalidOperationException" />
        private ContentSchema GetContentSchema(Content content, SchemaContext context, string path)
        {
            if (context.SchemasByContent.ContainsKey(content))
            {
                ContentSchema repeatedSchema = context.SchemasByContent[content];
                context.RepeatedSchemas.Add(repeatedSchema);
                return(repeatedSchema);
            }

            ContentSchema contentSchema = CreateContentSchema(content, path);

            context.SchemasByContent[content] = contentSchema;

            var qpFields = _fieldService.List(content.ContentId).ToArray();

            var fieldsToAdd = content.Fields
                              .Where(field => !(field is Dictionaries || field is BaseVirtualField) &&
                                     !context.IgnoredFields.Contains(Tuple.Create(content, field)));

            foreach (Field field in fieldsToAdd)
            {
                if (field.FieldName == null)
                {
                    throw new InvalidOperationException(
                              $"FieldName is null: {new { field.FieldId, field.FieldName }}");
                }

                var qpField = field is BackwardRelationField
                        ? _fieldService.Read(field.FieldId)
                        : qpFields.SingleOrDefault(f => f.Id == field.FieldId);

                if (qpField == null)
                {
                    throw new InvalidOperationException(
                        $@"There is a field id={field.FieldId} specified in the definition and missing in the content id={content.ContentId}"
                              );
                }
                if (qpField.ExactType != FieldExactTypes.DynamicImage)
                {
                    contentSchema.Fields[field.FieldName] = GetFieldSchema(field, qpField, context, path);
                }
            }

            if (content.LoadAllPlainFields)
            {
                var qpFieldsToAdd = qpFields
                                    .Where(qpField => qpField.RelationType == Quantumart.QP8.BLL.RelationType.None &&
                                           qpField.ExactType != FieldExactTypes.DynamicImage &&
                                           content.Fields.All(field => field.FieldId != qpField.Id) &&
                                           !context.IgnoredFields
                                           .Any(tuple => tuple.Item1.Equals(content) &&
                                                tuple.Item2.FieldId == qpField.Id));

                foreach (var qpField in qpFieldsToAdd)
                {
                    contentSchema.Fields[qpField.Name] = GetFieldSchema(null, qpField, context, path);
                }
            }

            contentSchema.DisplayFieldName = contentSchema.Fields.Values
                                             .OfType <PlainFieldSchema>()
                                             .Where(f => f.FieldType == FieldExactTypes.String)
                                             .OrderByDescending(f => f.ViewInList)
                                             .ThenBy(f => f.FieldOrder)
                                             .Select(f => f.FieldName)
                                             .FirstOrDefault();

            return(contentSchema);
        }
Exemple #10
0
        private int[] GetParentArticleIds(int childContentId, int[] childArticleIds, Field parentField, out int parentsContentId)
        {
            if (childArticleIds == null || childArticleIds.Length == 0)
            {
                parentsContentId = 0;

                return(new int[0]);
            }

            if (parentField is BackwardRelationField)
            {
                var childArticleField = _fieldService.Read(parentField.FieldId);

                if (!childArticleField.RelateToContentId.HasValue)
                {
                    throw new Exception("Некорректный BackwardRelationField: RelateToContentId у fieldId=" + childArticleField.Id + " null");
                }

                parentsContentId = childArticleField.RelateToContentId.Value;

                if (childArticleField.RelationType == RelationType.ManyToMany)
                {
                    return(GetManyToManyLinkedItems(childArticleField.LinkId, childArticleIds));
                }
                else if (childArticleField.RelationType == RelationType.OneToMany)
                {
                    return(_articleService.GetFieldValues(childArticleIds, childContentId, childArticleField.Name)
                           .Where(x => !string.IsNullOrEmpty(x))
                           .Select(int.Parse)
                           .Distinct()
                           .ToArray());
                }
                else
                {
                    throw new Exception("Некорректный BackwardRelationField с ID=" + parentField.FieldId);
                }
            }
            else if (parentField is ExtensionField)
            {
                var parentArticleField = _fieldService.Read(parentField.FieldId);

                parentsContentId = parentArticleField.ContentId;

                var childField = _fieldService.List(childContentId).Single(x => x.ClassifierId == parentField.FieldId);

                return(_articleService.GetFieldValues(childArticleIds, childContentId, childField.Name)
                       .Where(x => !string.IsNullOrEmpty(x))
                       .Select(int.Parse)
                       .ToArray());
            }
            else if (parentField is EntityField)
            {
                var parentArticleField = _fieldService.Read(parentField.FieldId);

                parentsContentId = parentArticleField.ContentId;

                switch (parentArticleField.RelationType)
                {
                case RelationType.OneToMany:

                    return(_articleService.GetRelatedItemsMultiple(parentField.FieldId, childArticleIds, true)
                           .SelectMany(x => Converter.ToIdArray(x.Value))
                           .Distinct()
                           .ToArray());

                case RelationType.ManyToMany:

                    return(GetManyToManyLinkedItems(parentArticleField.LinkId, childArticleIds));

                case RelationType.ManyToOne:

                    if (!parentArticleField.BackRelationId.HasValue)
                    {
                        throw new Exception("Связь ManyToMany некорректно настроена у fieldId=" + parentField.FieldId + ": BackRelationId null");
                    }

                    return(_articleService.GetFieldValues(childArticleIds, childContentId, parentArticleField.BackRelationId.Value)
                           .Where(x => !string.IsNullOrEmpty(x))
                           .Distinct()
                           .Select(int.Parse)
                           .ToArray());

                default:
                    throw new Exception("Связь типа " + parentArticleField.RelationType + " не поддерживается");
                }
            }
            else
            {
                throw new Exception("Тип поля " + parentField.GetType().Name + " не поддерживается");
            }
        }