예제 #1
0
        public ActionResult Add(int id)
        {
            if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage queries")))
            {
                return(new HttpUnauthorizedResult());
            }

            var viewModel = new PropertyAddViewModel {
                Id = id, Properties = _projectionManager.DescribeProperties()
            };

            return(View(viewModel));
        }
예제 #2
0
        public IEnumerable <PropertyDescriptor> GetFieldDescriptors(string entityType)
        {
            var category         = entityType + "ContentFields";
            var fieldDescriptors = _projectionManager.DescribeProperties().Where(x => x.Category == category).SelectMany(x => x.Descriptors).ToList();

            return(fieldDescriptors);
        }
예제 #3
0
        public bool CompareContent(ContentItem preContentItem, ContentItem newContentItem)
        {
            _defferences.Clear();
            var part = newContentItem.Parts.FirstOrDefault(p => p.PartDefinition.Name.Contains(preContentItem.ContentType));

            if (part == null)
            {
                return(false);
            }
            var fieldContext = new PropertyContext
            {
                State = FormParametersHelper.ToDynamic(string.Empty)
            };
            string category           = newContentItem.ContentType + "ContentFields";
            var    allFielDescriptors = _projectionManager.DescribeProperties().Where(p => p.Category == category).SelectMany(x => x.Descriptors).ToList();

            foreach (var field in part.Fields)
            {
                if (!field.PartFieldDefinition.Settings.ContainsKey(isAuditKey))
                {
                    continue;
                }
                bool isAudit = bool.Parse(field.PartFieldDefinition.Settings[isAuditKey]);
                if (!isAudit)
                {
                    continue;
                }
                if (_defferences.Keys.Contains(field.Name))
                {
                    continue;
                }
                var descriptor = allFielDescriptors.FirstOrDefault(d => d.Name.Text == field.Name + ":Value");
                if (descriptor == null)
                {
                    continue;
                }
                var preValue = descriptor.Property(fieldContext, preContentItem);
                var newValue = descriptor.Property(fieldContext, newContentItem);
                if (preValue != null && !string.IsNullOrEmpty(preValue.ToString()) &&
                    (newValue == null || string.IsNullOrEmpty(newValue.ToString())))
                {
                    _defferences.Add(field.Name, string.Format("Deleted {1} in {0}.", field.Name, preValue));
                }
                else if (preValue != null && newValue.ToString() != preValue.ToString() ||
                         preValue == null && newValue != null && !string.IsNullOrEmpty(newValue.ToString()))
                {
                    _defferences.Add(field.Name, string.Format("Changed {0} from {1} to {2}.", field.Name, preValue, newValue));
                }
            }
            return(_defferences.Count == 1);
        }
예제 #4
0
        private IEnumerable <JObject> GetLayoutComponents(ProjectionPart part, int skipCount, int pageCount)
        {
            // query
            var query = part.Record.QueryPartRecord;

            // applying layout
            var layout = part.Record.LayoutRecord;
            var tokens = new Dictionary <string, object> {
                { "Content", part.ContentItem }
            };
            var allFielDescriptors = _projectionManager.DescribeProperties().ToList();
            var fieldDescriptors   = layout.Properties.OrderBy(p => p.Position).Select(p => allFielDescriptors.SelectMany(x => x.Descriptors).Select(d => new { Descriptor = d, Property = p }).FirstOrDefault(x => x.Descriptor.Category == p.Category && x.Descriptor.Type == p.Type)).ToList();

            fieldDescriptors = fieldDescriptors.Where(c => c != null).ToList();
            var tokenizedDescriptors = fieldDescriptors.Select(fd => new { fd.Descriptor, fd.Property, State = FormParametersHelper.ToDynamic(_tokenizer.Replace(fd.Property.State, tokens)) }).ToList();

            // execute the query
            var contentItems = _projectionManager.GetContentItems(query.Id, skipCount, pageCount).ToList();

            // sanity check so that content items with ProjectionPart can't be added here, or it will result in an infinite loop
            contentItems = contentItems.Where(x => !x.Has <ProjectionPart>()).ToList();

            var layoutComponents = contentItems.Select(
                contentItem => {
                var result          = new JObject();
                result["ContentId"] = contentItem.Id;
                tokenizedDescriptors.ForEach(
                    d => {
                    var fieldContext = new PropertyContext {
                        State  = d.State,
                        Tokens = tokens
                    };
                    var shape         = d.Descriptor.Property(fieldContext, contentItem);
                    string text       = (shape == null) ? string.Empty : shape.ToString();
                    var filedName     = d.Property.GetFiledName();
                    result[filedName] = text;
                });
                return(result);
            }).ToList();

            return(layoutComponents);
        }
예제 #5
0
        public ActionResult Edit(int id)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageQueries, T("Not authorized to manage queries")))
            {
                return(new HttpUnauthorizedResult());
            }

            var layoutRecord = _repository.Get(id);

            if (layoutRecord == null)
            {
                return(HttpNotFound());
            }

            var layoutDescriptor = _projectionManager.DescribeLayouts().SelectMany(x => x.Descriptors).FirstOrDefault(x => x.Category == layoutRecord.Category && x.Type == layoutRecord.Type);

            // Build the form, and let external components alter it.
            var form = _formManager.Build(layoutDescriptor.Form) ?? Services.New.EmptyForm();

            var viewModel = new LayoutEditViewModel {
                Id              = id,
                QueryId         = layoutRecord.QueryPartRecord.Id,
                Category        = layoutDescriptor.Category,
                Type            = layoutDescriptor.Type,
                Description     = layoutRecord.Description,
                Display         = layoutRecord.Display,
                DisplayType     = String.IsNullOrWhiteSpace(layoutRecord.DisplayType) ? "Summary" : layoutRecord.DisplayType,
                Layout          = layoutDescriptor,
                Form            = form,
                GroupPropertyId = layoutRecord.GroupProperty == null ? 0 : layoutRecord.GroupProperty.Id
            };

            // Bind form with existing values.
            var parameters = FormParametersHelper.FromString(layoutRecord.State);

            _formManager.Bind(form, new DictionaryValueProvider <string>(parameters, CultureInfo.InvariantCulture));

            #region Load Fields

            var fieldEntries = new List <PropertyEntry>();
            var allFields    = _projectionManager.DescribeProperties().SelectMany(x => x.Descriptors);

            foreach (var field in layoutRecord.Properties)
            {
                var fieldCategory = field.Category;
                var fieldType     = field.Type;

                var f = allFields.FirstOrDefault(x => fieldCategory == x.Category && fieldType == x.Type);
                if (f != null)
                {
                    fieldEntries.Add(
                        new PropertyEntry {
                        Category         = f.Category,
                        Type             = f.Type,
                        PropertyRecordId = field.Id,
                        DisplayText      = String.IsNullOrWhiteSpace(field.Description) ? f.Display(new PropertyContext {
                            State = FormParametersHelper.ToDynamic(field.State)
                        }).Text : field.Description,
                        Position = field.Position
                    });
                }
            }

            viewModel.Properties = fieldEntries.OrderBy(f => f.Position);

            #endregion

            return(View(viewModel));
        }