public ProjectionEditViewModel GetProjectionViewModel(int id) { var viewModel = new ProjectionEditViewModel(); //Get Projection&QueryPart var projectionItem = _contentManager.Get(id, VersionOptions.Latest); var projectionPart = projectionItem.As<ProjectionPart>(); var queryId = projectionPart.Record.QueryPartRecord.Id; var queryPart = _contentManager.Get<QueryPart>(queryId, VersionOptions.Latest); var listViewPart = projectionItem.As<ListViewPart>(); viewModel.Id = id; viewModel.ItemContentType = listViewPart.ItemContentType; viewModel.DisplayName = listViewPart.As<TitlePart>().Title; viewModel.VisableTo = listViewPart.VisableTo; viewModel.PageRowCount = projectionPart.Record.ItemsPerPage; viewModel.IsDefault = listViewPart.IsDefault; //Get AllFields viewModel.Fields = GetFieldDescriptors(listViewPart.ItemContentType); var sortCriterion = queryPart.SortCriteria.FirstOrDefault(); if (sortCriterion != null) { var state = FormParametersHelper.ToDynamic(sortCriterion.State); viewModel.SortedBy = state.Type; var ascending = (bool) state.Sort; viewModel.SortMode = ascending ? "Asc" : "Desc"; } return viewModel; }
public ActionResult EditPOST(int id, ProjectionEditViewModel viewModel, string picklist, string returnUrl) { if (id == 0) { id = _projectionService.CreateProjection(viewModel.Name); } var pickArray = picklist.Split(new[] {'$'}, StringSplitOptions.RemoveEmptyEntries); _projectionService.EditPost(id, viewModel, pickArray); return Json(new { id = id}); }
public ProjectionEditViewModel GetTempProjection(string entityType) { var viewModel = new ProjectionEditViewModel {Name = entityType, DisplayName = string.Empty}; //Get all field var contentPart = _contentDefinitionManager.GetPartDefinition(entityType); viewModel.AllFields = contentPart == null ? new List<ContentPartFieldDefinition>() : contentPart.Fields; return viewModel; }
public void OnCreated(string entityName) { var fields = _projectionService.GetFieldDescriptors(entityName).Select(x => x.Type); var viewModel = new ProjectionEditViewModel { ItemContentType = entityName, DisplayName = entityName + " DefaultView", PageRowCount = 50, IsDefault = true }; _projectionService.EditPost(0, viewModel, fields); }
public void OnCreated(string entityName) { var id = _projectionService.CreateProjection(entityName); var fields = _contentDefinitionManager.GetPartDefinition(entityName).Fields.Select(x => x.Name); var viewModel = new ProjectionEditViewModel { Name = entityName, DisplayName = entityName + "DefaultView", PageRowCount = 50 }; _projectionService.EditPost(id, viewModel, fields); _viewPartService.SetView(entityName, id); }
public ActionResult Create(string id) { var pluralService = PluralizationService.CreateService(new CultureInfo("en-US")); if (pluralService.IsPlural(id)) { id = pluralService.Singularize(id); } if (!_contentMetadataService.CheckEntityPublished(id)) { return Content(T("The \"{0}\" hasn't been published!", id).Text); } var viewModel = new ProjectionEditViewModel { ItemContentType = id, DisplayName = string.Empty, Fields = _projectionService.GetFieldDescriptors(id) }; return View("Edit", viewModel); }
public ProjectionEditViewModel GetProjectionViewModel(int id) { var viewModel = new ProjectionEditViewModel(); //Get Projection&QueryPart var projectionItem = _contentManager.Get(id, VersionOptions.Latest); var projectionPart = projectionItem.As<ProjectionPart>(); var queryId = projectionPart.Record.QueryPartRecord.Id; var queryItem = _contentManager.Get(queryId, VersionOptions.Latest); var queryPart = queryItem.As<QueryPart>(); viewModel.Id = id; viewModel.Name = projectionItem.As<TitlePart>().Title; viewModel.DisplayName = queryPart.Name; viewModel.QueryViewModel = GetQueryViewModel(queryPart); //Get LayoutViewModel; var layoutRecord = projectionPart.Record.LayoutRecord; viewModel.LayoutViewModel = GetLayoutEditViewModel(layoutRecord); //Get AllFields var contentPart = _contentDefinitionManager.GetPartDefinition(viewModel.Name); viewModel.AllFields = contentPart == null ? new BindingList<ContentPartFieldDefinition>() : contentPart.Fields; var sortCriteria = queryPart.SortCriteria.FirstOrDefault(); if (sortCriteria != null) { viewModel.SortedBy = sortCriteria.Type; var regex = new Regex("<Sort>(.+?)</Sort>"); var matche = regex.Match(sortCriteria.State); viewModel.SortMode = matche.Value.Contains("true") ? "Desc" : "Asc"; } var layoutPropertyPart = _layoutPropertyService.GetLayoutPropertyByQueryid(queryPart.Id); if (layoutPropertyPart != null) { viewModel.VisableTo = layoutPropertyPart.VisableTo; viewModel.PageRowCount = layoutPropertyPart.PageRowCount; } return viewModel; }
public void EditPost(int id, ProjectionEditViewModel viewModel, IEnumerable<string> pickedFileds) { if (pickedFileds == null) { pickedFileds = new List<string>(); } var projectionPart = _contentManager.Get<ProjectionPart>(id, VersionOptions.Latest); var queryId = projectionPart.Record.QueryPartRecord.Id; var queryPart = _contentManager.Get<QueryPart>(queryId, VersionOptions.Latest); //Post DisplayName queryPart.As<TitlePart>().Title = viewModel.DisplayName; //Post Selected Fields var layoutRecord = projectionPart.Record.LayoutRecord; layoutRecord.Properties.Clear(); string category = viewModel.Name + "ContentFields"; const string settingName = "CoeveryTextFieldSettings.IsDispalyField"; var allFields = _contentDefinitionManager.GetPartDefinition(viewModel.Name).Fields.ToList(); foreach (var property in pickedFileds) { var field = allFields.FirstOrDefault(c => c.Name == property); if (field == null) { continue; } var propertyRecord = new PropertyRecord { Category = category, Type = string.Format("{0}.{1}.", viewModel.Name, property), Description = field.DisplayName, Position = layoutRecord.Properties.Count, State = GetPropertyState(property), LinkToContent = field.Settings.ContainsKey(settingName) && bool.Parse(field.Settings[settingName]) }; layoutRecord.Properties.Add(propertyRecord); } 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); } // VisableTo and pageRowCount var layoutPropertyRecord = new LayoutPropertyRecord { VisableTo = viewModel.VisableTo, PageRowCount = viewModel.PageRowCount, QueryPartRecord_id = queryPart.Id }; _layoutPropertyService.CreateLayoutProperty(layoutPropertyRecord); }
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; }