Esempio n. 1
0
        public int CreateProjection(string entityType) {
            var projectionItem = _contentManager.New("ProjectionPage");
            var queryItem = _contentManager.New("Query");
            var projectionPart = projectionItem.As<ProjectionPart>();
            var queryPart = queryItem.As<QueryPart>();
            queryPart.As<TitlePart>().Title = entityType;
            projectionPart.As<TitlePart>().Title = entityType;
            _contentManager.Create(queryItem);
            projectionPart.Record.QueryPartRecord = queryPart.Record;
            _contentManager.Create(projectionItem);

            var layoutRecord = new LayoutRecord {
                Category = "Html",
                Type = "ngGrid",
                Description = "DefaultLayoutFor" + queryPart.Name,
                Display = 1
            };
            queryPart.Layouts.Add(layoutRecord);
            projectionPart.Record.LayoutRecord = layoutRecord;

            var filterGroup = new FilterGroupRecord();
            queryPart.Record.FilterGroups.Clear();
            queryPart.Record.FilterGroups.Add(filterGroup);
            var filterRecord = new FilterRecord {
                Category = "Content",
                Type = "ContentTypes",
                Position = filterGroup.Filters.Count,
                State = GetContentTypeFilterState(entityType)
            };
            filterGroup.Filters.Add(filterRecord);
            return projectionItem.Id;
        }
Esempio n. 2
0
        public ActionResult CreatePost(LayoutEditViewModel model, FormCollection formCollection) {
            if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage queries")))
                return new HttpUnauthorizedResult();

            // validating form values
            model.Layout = _projectionManager.DescribeLayouts().SelectMany(x => x.Descriptors).FirstOrDefault(x => x.Category == model.Category && x.Type == model.Type);

            _formManager.Validate(new ValidatingContext { FormName = model.Layout.Form, ModelState = ModelState, ValueProvider = ValueProvider });

            var form = _formManager.Build(model.Layout.Form) ?? Services.New.EmptyForm();
            _formManager.Bind(form, formCollection);

            model.Form = form;

            if (ModelState.IsValid) {
                var layoutRecord = new LayoutRecord { Category = model.Category, Type = model.Type };
                var query = _queryService.GetQuery(model.QueryId);
                query.Layouts.Add(layoutRecord);

                var dictionary = formCollection.AllKeys.ToDictionary(key => key, formCollection.Get);

                // save form parameters
                layoutRecord.State = FormParametersHelper.ToString(dictionary);
                layoutRecord.Description = model.Description;
                layoutRecord.Display = model.Display;
                layoutRecord.DisplayType = model.DisplayType;

                Services.ContentManager.Flush();

                Services.Notifier.Information(T("Layout Created"));

                return RedirectToAction("Edit", new { id = layoutRecord.Id });
            }

            return View(model);
        }
Esempio n. 3
0
        private LayoutEditViewModel GetLayoutEditViewModel(LayoutRecord layoutRecord) {
            if (layoutRecord == null) {
                return null;
            }

            var layoutDescriptor = _projectionManager.DescribeLayouts()
                .SelectMany(x => x.Descriptors)
                .First(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 = layoutRecord.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));

            var fieldEntries = layoutRecord.Properties
                .Select(field => new PropertyEntry {
                    Category = field.Category,
                    Type = field.Type,
                    PropertyRecordId = field.Id,
                    DisplayText = field.Description,
                    Position = field.Position
                }).ToList();
            viewModel.Properties = fieldEntries.OrderBy(f => f.Position).ToList();
            return viewModel;
        }
Esempio n. 4
0
        private ProjectionPart CreateProjection(string typeName, IEnumerable<string> properties) {
            var projectionItem = _contentManager.New("ProjectionPage");
            var queryItem = _contentManager.New("Query");
            var projectionPart = projectionItem.As<ProjectionPart>();
            var queryPart = queryItem.As<QueryPart>();
            _contentManager.Create(queryItem);

            projectionPart.Record.QueryPartRecord = queryPart.Record;
            _contentManager.Create(projectionItem);

            var layoutRecord = new LayoutRecord {Category = "Html", Type = "ngGrid"};
            queryPart.Record.Layouts.Add(layoutRecord);
            projectionPart.Record.LayoutRecord = layoutRecord;

            var filterGroup = new FilterGroupRecord();
            queryPart.Record.FilterGroups.Clear();
            queryPart.Record.FilterGroups.Add(filterGroup);
            var filterRecord = new FilterRecord {
                Category = "Content",
                Type = "ContentTypes",
                Position = filterGroup.Filters.Count,
                State = string.Format("<Form><ContentTypes>{0}</ContentTypes></Form>", typeName)
            };
            filterGroup.Filters.Add(filterRecord);

            UpdateLayoutProperties(typeName, layoutRecord, properties);
            return projectionPart;
        }
Esempio n. 5
0
 private void UpdateLayoutProperties(string typeName, LayoutRecord layoutRecord, IEnumerable<string> properties) {
     layoutRecord.Properties.Clear();
     if (properties == null) {
         return;
     }
     string category = typeName + "ContentFields";
     const string settingName = "CoeveryTextFieldSettings.IsDispalyField";
     var allFields = _contentDefinitionManager.GetPartDefinition(typeName).Fields.ToList();
     foreach (var property in properties) {
         var field = allFields.FirstOrDefault(c => c.Name == property);
         if (field == null) {
             continue;
         }
         var propertyRecord = new PropertyRecord {
             Category = category,
             Type = string.Format("{0}.{1}.", typeName, property),
             Description = field.DisplayName,
             Position = layoutRecord.Properties.Count,
             LinkToContent = field.Settings.ContainsKey(settingName) && bool.Parse(field.Settings[settingName])
         };
         layoutRecord.Properties.Add(propertyRecord);
     }
 }
Esempio n. 6
0
 private void UpdateLayoutProperties(string entityName, ref LayoutRecord layout, string category, string settingName, IEnumerable<string> pickedFileds) {
     var allFields = _contentDefinitionManager.GetPartDefinition(entityName).Fields.ToList();
     const string fieldTypeFormat = "{0}.{1}.";
     foreach (var property in pickedFileds) {
         var names = property.Split('.');
         var propertyMatch = string.Format(fieldTypeFormat, names[0], names[1]);
         var field = allFields.FirstOrDefault(c =>
             string.Format(fieldTypeFormat, entityName, c.Name) == propertyMatch);
         if (field == null) {
             continue;
         }
         var fieldStateProvider = _fieldToPropertyStateProviders.FirstOrDefault(provider=>provider.CanHandle(field.FieldDefinition.Name));
         if (fieldStateProvider == null) {
             throw new NotSupportedException("The field type \""+ field.FieldDefinition.Name + "\" is not supported!");
         }
         var propertyRecord = new PropertyRecord {
             Category = category,
             Type = property,
             Description = field.DisplayName,
             Position = layout.Properties.Count,
             State = fieldStateProvider.GetPropertyState(field.FieldDefinition.Name, property, field.Settings),
             LinkToContent = field.Settings.ContainsKey(settingName) && bool.Parse(field.Settings[settingName])
         };
         layout.Properties.Add(propertyRecord);
     }
 }
Esempio n. 7
0
        public int EditPost(int id, ProjectionEditViewModel viewModel, IEnumerable<string> pickedFileds) {
            ListViewPart listViewPart;
            ProjectionPart projectionPart;
            QueryPart queryPart;
            if (id == 0) {
                listViewPart = _contentManager.New<ListViewPart>("ListViewPage");
                listViewPart.ItemContentType = viewModel.ItemContentType;
                queryPart = _contentManager.New<QueryPart>("Query");

                var layout = new LayoutRecord {
                    Category = "Html",
                    Type = "ngGrid",
                    Description = "DefaultLayoutFor" + queryPart.Name,
                    Display = 1
                };

                queryPart.Layouts.Add(layout);
                projectionPart = listViewPart.As<ProjectionPart>();
                projectionPart.Record.LayoutRecord = layout;
                projectionPart.Record.QueryPartRecord = queryPart.Record;

                var filterGroup = new FilterGroupRecord();
                queryPart.Record.FilterGroups.Add(filterGroup);
                var filterRecord = new FilterRecord {
                    Category = "Content",
                    Type = "ContentTypes",
                    Position = filterGroup.Filters.Count,
                    State = GetContentTypeFilterState(viewModel.ItemContentType)
                };
                filterGroup.Filters.Add(filterRecord);

                _contentManager.Create(queryPart.ContentItem);
                _contentManager.Create(projectionPart.ContentItem);
            }
            else {
                listViewPart = _contentManager.Get<ListViewPart>(id, VersionOptions.Latest);
                projectionPart = listViewPart.As<ProjectionPart>();
                var queryId = projectionPart.Record.QueryPartRecord.Id;
                queryPart = _contentManager.Get<QueryPart>(queryId, VersionOptions.Latest);
            }

            if (pickedFileds == null) {
                pickedFileds = new List<string>();
            }

            listViewPart.VisableTo = viewModel.VisableTo;
            listViewPart.As<TitlePart>().Title = viewModel.DisplayName;
            listViewPart.IsDefault = viewModel.IsDefault;
            queryPart.Name = "Query for Public View";

            projectionPart.Record.ItemsPerPage = viewModel.PageRowCount;
            //Post Selected Fields
            var layoutRecord = projectionPart.Record.LayoutRecord;
            layoutRecord.Properties.Clear();

            var category = viewModel.ItemContentType + "ContentFields";
            const string settingName = "CoeveryTextFieldSettings.IsDispalyField";
            try {
                UpdateLayoutProperties(viewModel.ItemContentType, ref layoutRecord, category, settingName, pickedFileds);
            }
            catch (Exception exception) {
                Services.Notifier.Add(NotifyType.Error,T(exception.Message));
            }
            layoutRecord.State = GetLayoutState(queryPart.Id, layoutRecord.Properties.Count, layoutRecord.Description);
            // sort
            queryPart.SortCriteria.Clear();
            if (!string.IsNullOrEmpty(viewModel.SortedBy)) {
                var sortCriterionRecord = new SortCriterionRecord {
                    Category = category,
                    Type = viewModel.SortedBy,
                    Position = queryPart.SortCriteria.Count,
                    State = GetSortState(viewModel.SortedBy, viewModel.SortMode),
                    Description = viewModel.SortedBy + " " + viewModel.SortMode
                };
                queryPart.SortCriteria.Add(sortCriterionRecord);
            }
            return listViewPart.Id;
        }
Esempio n. 8
0
		private void LayoutStaffProfileQuery(QueryPart staffProfileQuery)
		{
			var layoutDictionary = new Dictionary<string, string>();
			layoutDictionary.Add("QueryId", staffProfileQuery.Id.ToString());
			layoutDictionary.Add("Category", "Html");
			layoutDictionary.Add("Type", "List");
			layoutDictionary.Add("Description", "List");
			layoutDictionary.Add("Display", "0");
			layoutDictionary.Add("DisplayType", "Summary");

			LayoutRecord layout = staffProfileQuery.Layouts.FirstOrDefault();
			if (layout == null)
			{
				layout = new LayoutRecord()
				{
					Category = "Html",
					Type = "List",
					Description = "List",
					Display = 0,
					DisplayType = "Summary",
				};
				staffProfileQuery.Layouts.Add(layout);
			}
			layout.State = FormParametersHelper.ToString(layoutDictionary);
		}