public ActionResult CreatePartPOST(CreatePartViewModel viewModel) { if (!Services.Authorizer.Authorize(Permissions.EditContentTypes, T("无权限."))) { return(new HttpUnauthorizedResult()); } if (_contentDefinitionManager.GetPartDefinition(viewModel.Name) != null) { ModelState.AddModelError("Name", T("内容元件 '{0}'. 已存在.", viewModel.Name).ToString()); } if (!ModelState.IsValid) { return(View(viewModel)); } var partViewModel = _contentDefinitionService.AddPart(viewModel); if (partViewModel == null) { Services.Notifier.Information(T("内容元件创建失败,请输入正确的名称.")); return(View(viewModel)); } Services.Notifier.Information(T("内容元件 \"{0}\" 创建成功.", partViewModel.Name)); return(RedirectToAction("EditPart", new { id = partViewModel.Name })); }
public void Describe(dynamic context) { context.For("Site", T("Site Settings"), T("Tokens for Site Settings")) .Token("SiteName", T("Site Name"), T("The name of the site.")) .Token("SuperUser", T("Super User"), T("The name of the super user.")) .Token("Culture", T("Site Culture"), T("The current culture of the site.")) .Token("BaseUrl", T("Base Url"), T("The base url the site.")) .Token("TimeZone", T("Time Zone"), T("The current time zone of the site.")) ; // Token descriptors for fields var customSettingsPart = _contentDefinitionManager.GetPartDefinition("Site"); if (customSettingsPart != null && customSettingsPart.Fields.Any()) { var partContext = context.For("Site"); foreach (var partField in customSettingsPart.Fields) { var field = partField; var tokenName = field.Name; // the token is chained with the technical name partContext.Token(tokenName, T("{0}", field.Name), T("The setting named {0}.", partField.DisplayName), field.Name); } } }
public ActionResult EditOneToMany(string entityName, int relationId) { if (!Services.Authorizer.Authorize(Permissions.EditContent, T("Not allowed to edit a content."))) { return(new HttpUnauthorizedResult()); } var oneToMany = _relationshipService.GetOneToMany(relationId); if (oneToMany == null || oneToMany.Id == 0) { return(ResponseError("Relationship not found")); } var part = _contentDefinitionManager.GetPartDefinition(oneToMany.Relationship.RelatedEntity.Name); var fields = part == null ? new List <SelectListItem>() : part.Fields.Select(x => new SelectListItem { Text = x.DisplayName, Value = x.Name }); return(View("CreateOneToMany", new OneToManyRelationshipModel { IsCreate = false, Name = oneToMany.Relationship.Name, DeleteOption = (OneToManyDeleteOption)oneToMany.DeleteOption, PrimaryEntity = oneToMany.Relationship.PrimaryEntity.Name, RelatedEntity = oneToMany.Relationship.RelatedEntity.Name, RelatedListLabel = oneToMany.RelatedListLabel, ShowRelatedList = oneToMany.ShowRelatedList, ColumnFieldList = oneToMany.RelatedListProjection.LayoutRecord.Properties.Select(x => x.GetFiledName()).ToArray(), Fields = fields })); }
public async Task <ActionResult> CreatePartPOST(CreatePartViewModel viewModel) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContentTypes)) { return(Unauthorized()); } if (_contentDefinitionManager.GetPartDefinition(viewModel.Name) != null) { ModelState.AddModelError("Name", S["Cannot add part named '{0}'. It already exists.", viewModel.Name]); } if (!ModelState.IsValid) { return(View(viewModel)); } var partViewModel = _contentDefinitionService.AddPart(viewModel); if (partViewModel == null) { _notifier.Information(T["The content part could not be created."]); return(View(viewModel)); } _notifier.Success(T["The \"{0}\" content part has been created.", partViewModel.Name]); return(RedirectToAction("EditPart", new { id = partViewModel.Name })); }
public ActionResult CreatePartPOST(CreatePartViewModel viewModel) { if (!Services.Authorizer.Authorize(Permissions.EditContentTypes, T("Not allowed to create a content part."))) { return(new HttpUnauthorizedResult()); } if (_contentDefinitionManager.GetPartDefinition(viewModel.Name) != null) { ModelState.AddModelError("Name", T("Cannot add part named '{0}'. It already exists.", viewModel.Name).ToString()); } if (!ModelState.IsValid) { return(View(viewModel)); } var partViewModel = _contentDefinitionService.AddPart(viewModel); if (partViewModel == null) { Services.Notifier.Error(T("The content part could not be created.")); return(View(viewModel)); } Services.Notifier.Success(T("The \"{0}\" content part has been created.", partViewModel.Name)); return(RedirectToAction("EditPart", new { id = partViewModel.Name })); }
/* * <ContentDefinition> * <Types> * <Blog creatable="true"> * <Body format="abodyformat"/> * </Blog> * </Types> * <Parts> * </Parts> * </ContentDefinition> */ // Set type settings and attach parts to types. // Create dynamic parts. public override void Execute(RecipeExecutionContext context) { foreach (var metadataElement in context.RecipeStep.Step.Elements()) { Logger.Debug("Processing element '{0}'.", metadataElement.Name.LocalName); switch (metadataElement.Name.LocalName) { case "Types": foreach (var element in metadataElement.Elements()) { var typeElement = element; var typeName = XmlConvert.DecodeName(element.Name.LocalName); Logger.Information("Importing content type '{0}'.", typeName); try { _contentDefinitonEventHandlers.ContentTypeImporting(new ContentTypeImportingContext { ContentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(typeName), ContentTypeName = typeName }); _contentDefinitionManager.AlterTypeDefinition(typeName, alteration => _contentDefinitionReader.Merge(typeElement, alteration)); _contentDefinitonEventHandlers.ContentTypeImported(new ContentTypeImportedContext { ContentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(typeName) }); } catch (Exception ex) { Logger.Error(ex, "Error while importing content type '{0}'.", typeName); throw; } } break; case "Parts": foreach (var element in metadataElement.Elements()) { var partElement = element; var partName = XmlConvert.DecodeName(element.Name.LocalName); Logger.Information("Importing content part '{0}'.", partName); try { _contentDefinitonEventHandlers.ContentPartImporting(new ContentPartImportingContext { ContentPartDefinition = _contentDefinitionManager.GetPartDefinition(partName), ContentPartName = partName }); _contentDefinitionManager.AlterPartDefinition(partName, alteration => _contentDefinitionReader.Merge(partElement, alteration)); _contentDefinitonEventHandlers.ContentPartImported(new ContentPartImportedContext { ContentPartDefinition = _contentDefinitionManager.GetPartDefinition(partName) }); } catch (Exception ex) { Logger.Error(ex, "Error while importing content part '{0}'.", partName); throw; } } break; default: Logger.Warning("Unrecognized element '{0}' encountered; skipping", metadataElement.Name.LocalName); break; } } }
public string GetReferenceField(string entityName, string relationName) { var reference = _contentDefinitionManager .GetPartDefinition(entityName) .Fields.FirstOrDefault(field => field.FieldDefinition.Name == "ReferenceField" && field.Settings.TryGetModel <ReferenceFieldSettings>().RelationshipName == relationName); return(reference == null ? null : reference.Name); }
/* * <Metadata> * <Types> * <Blog creatable="true"> * <Body format="abodyformat"/> * </Blog> * </Types> * <Parts> * </Parts> * </Metadata> */ // Set type settings and attach parts to types. // Create dynamic parts. public void ExecuteRecipeStep(RecipeContext recipeContext) { if (!String.Equals(recipeContext.RecipeStep.Name, "Metadata", StringComparison.OrdinalIgnoreCase)) { return; } foreach (var metadataElement in recipeContext.RecipeStep.Step.Elements()) { switch (metadataElement.Name.LocalName) { case "Types": foreach (var element in metadataElement.Elements()) { var typeElement = element; var typeName = XmlConvert.DecodeName(element.Name.LocalName); _contentDefinitonEventHandlers.ContentTypeImporting(new ContentTypeImportingContext { ContentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(typeName), ContentTypeName = typeName }); _contentDefinitionManager.AlterTypeDefinition(typeName, alteration => _contentDefinitionReader.Merge(typeElement, alteration)); _contentDefinitonEventHandlers.ContentTypeImported(new ContentTypeImportedContext { ContentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(typeName) }); } break; case "Parts": // create dynamic part. foreach (var element in metadataElement.Elements()) { var partElement = element; var partName = XmlConvert.DecodeName(element.Name.LocalName); _contentDefinitonEventHandlers.ContentPartImporting(new ContentPartImportingContext { ContentPartDefinition = _contentDefinitionManager.GetPartDefinition(partName), ContentPartName = partName }); _contentDefinitionManager.AlterPartDefinition(partName, alteration => _contentDefinitionReader.Merge(partElement, alteration)); _contentDefinitonEventHandlers.ContentPartImported(new ContentPartImportedContext { ContentPartDefinition = _contentDefinitionManager.GetPartDefinition(partName) }); } break; default: Logger.Error("Unrecognized element {0} encountered in step Metadata. Skipping.", metadataElement.Name.LocalName); break; } } recipeContext.Executed = true; }
public ActionResult Index(string id, string returnUrl) { if (string.IsNullOrEmpty(id)) { throw new HttpResponseException(HttpStatusCode.BadRequest); } if (!_contentMetadataService.CheckEntityPublished(id)) { return(Content(T("The \"{0}\" hasn't been published!", id).Text)); } var contentItem = _contentManager.New(id); dynamic model = _contentManager.BuildEditor(contentItem); var contentTypeDefinition = contentItem.TypeDefinition; string layout = contentTypeDefinition.Settings.ContainsKey("Layout") ? contentTypeDefinition.Settings["Layout"] : string.Empty; layout = string.IsNullOrEmpty(layout) ? "<fd-section section-columns=\"1\" section-columns-width=\"6:6\" section-title=\"Sample Title\"><fd-row><fd-column></fd-column></fd-row></fd-section>" : layout; var viewModel = Services.New.ViewModel(); viewModel.Layout = layout; viewModel.DisplayName = contentItem.TypeDefinition.DisplayName; var templates = new List <dynamic>(); var fields = _contentDefinitionManager.GetPartDefinition(id).Fields .Select(x => new FieldViewModel { DisplayName = x.DisplayName, Name = x.Name }) .ToList(); foreach (var item in model.Content.Items) { if (item.TemplateName != null && item.TemplateName.StartsWith("Fields/")) { templates.Add(item); } else if (item.TemplateName == "Parts/Relationship.Edit") { templates.Add(item); var name = item.ContentPart.GetType().Name; fields.Add(new FieldViewModel { Name = name, DisplayName = _contentDefinitionManager.GetPartDefinition(name).Settings["DisplayName"] }); } } viewModel.Templates = templates; viewModel.Fields = fields; return(View((object)viewModel)); }
public EditPartViewModel GetPart(string name) { var contentPartDefinition = _contentDefinitionManager.GetPartDefinition(name); if (contentPartDefinition == null) { return(null); } var viewModel = new EditPartViewModel(contentPartDefinition); return(viewModel); }
public EditPartViewModel GetPart(string name) { var contentPartDefinition = _contentDefinitionManager.GetPartDefinition(name); if (contentPartDefinition == null) { return(null); } var viewModel = new EditPartViewModel(contentPartDefinition) { Templates = _contentDefinitionEditorEvents.PartEditor(contentPartDefinition) }; return(viewModel); }
// GET api/<controller> public IEnumerable <JObject> Get(string id, string fieldName) { var partDefinition = _contentDefinitionManager.GetPartDefinition(id); if (partDefinition == null) { return(null); } var fieldDefinition = partDefinition.Fields.FirstOrDefault(x => x.Name == fieldName); if (fieldDefinition == null) { return(null); } var optionSetId = int.Parse(fieldDefinition.Settings["OptionSetFieldSettings.OptionSetId"]); var resultArr = _optionSetService.GetOptionItems(optionSetId); var items = new List <JObject>(); foreach (var result in resultArr) { var item = new JObject(); item["ID"] = result.Id; item["DisplayText"] = result.Name; items.Add(item); } return(items); }
public override IEnumerable <TemplateViewModel> PartFieldEditorUpdate( ContentPartFieldDefinitionBuilder builder, IUpdateModel updateModel) { if (_typeHasConfigPart) { var settings = new FrontendEditorConfigurationSettings(); if (updateModel.TryUpdateModel(settings, "FrontendEditorConfigurationSettings", null, null)) { FrontendEditorConfigurationSettings.SetValues(builder, settings.AllowFrontEndEdit); // Update the type settings var partDefinition = _contentDefinitionManager.GetPartDefinition(builder.PartName); var typeDefinition = _typeBuilder.Current; // At this stage, the settings in the FieldDefinition are not updated, so the IFrontEndProfileService // has no way of knowing whether the value of settings.AllowFrontEndEdit has changed. We need to pass // it along to be used. var fieldPlacements = GetEditorPlacement(typeDefinition, partDefinition, builder.Current, settings.AllowFrontEndEdit); if (fieldPlacements.Any()) { UpdateFrontEndPlacements(typeDefinition, fieldPlacements); //// schedules a re-evaluation of the shell //_settingsManagerEventHandlers.Value.Invoke(x => x.Saved(_shellSettings), Logger); } } yield return(DefinitionTemplate(settings)); } }
public async Task <IActionResult> List(string part, string field, string query) { if (string.IsNullOrWhiteSpace(part) || string.IsNullOrWhiteSpace(field)) { return(BadRequest("Part and field are required parameters")); } var partFieldDefinition = _contentDefinitionManager.GetPartDefinition(part)?.Fields .FirstOrDefault(f => f.Name == field); var fieldSettings = partFieldDefinition?.Settings.ToObject <ContentPickerFieldSettings>(); if (fieldSettings == null) { return(BadRequest("Unable to find field definition")); } var editor = partFieldDefinition.Editor() ?? "Default"; var resultProvider = _resultProviders.FirstOrDefault(p => p.Name == editor); if (resultProvider == null) { return(new ObjectResult(new List <ContentPickerResult>())); } var results = await resultProvider.Search(new ContentPickerSearchContext { Query = query, ContentTypes = fieldSettings.DisplayedContentTypes, PartFieldDefinition = partFieldDefinition }); return(new ObjectResult(results)); }
private bool UpdateDependenySetting(string entityName, string controlFieldName, string dependentFieldName) { var part = _contentDefinitionManager.GetPartDefinition(entityName); if (part == null) { return(false); } var control = part.Fields.FirstOrDefault(x => x.Name == controlFieldName); if (control == null) { return(false); } control.Settings[control.FieldDefinition.Name + "Settings.DependencyMode"] = DependentType.Control.ToString(); var dependent = part.Fields.FirstOrDefault(x => x.Name == dependentFieldName); if (dependent == null) { return(false); } dependent.Settings["OptionSetFieldSettings.DependencyMode"] = DependentType.Dependent.ToString(); _contentDefinitionManager.StorePartDefinition(part); return(true); }
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); } }
public IEnumerable <JObject> Get(string id, string fieldName) { var partDefinition = _contentDefinitionManager.GetPartDefinition(id); if (partDefinition == null) { return(null); } var fieldDefinition = partDefinition.Fields.FirstOrDefault(x => x.Name == fieldName); if (fieldDefinition == null) { return(null); } var queryId = int.Parse(fieldDefinition.Settings["ReferenceFieldSettings.QueryId"]); var items = new List <JObject>(); var contentItems = _projectionManager.GetContentItems(queryId); foreach (var contentItem in contentItems) { var item = new JObject(); item["DisplayText"] = _contentManager.GetItemMetadata(contentItem).DisplayText; item["Id"] = contentItem.Id; items.Add(item); } return(items); }
public static void AlterPartDefinition(this IContentDefinitionManager manager, string name, Action <ContentPartDefinitionBuilder> alteration) { var partDefinition = manager.GetPartDefinition(name) ?? new ContentPartDefinition(name); var builder = new ContentPartDefinitionBuilder(partDefinition); alteration(builder); manager.StorePartDefinition(builder.Build()); }
private void ApplyCriterionForField( SortCriterionContext context, SortCriterionConfiguration criterion) { // This uses the logic from ContentFieldsSortCriterion var partDefinition = _contentDefinitionManager.GetPartDefinition(criterion.PartName); if (partDefinition == null) { Logger.Error(T("Impossible to find a part definition with name {0}.", criterion.PartName).Text); } else { var fieldDefinition = partDefinition.Fields .FirstOrDefault(fd => fd.Name.Equals(criterion.FieldName)); if (fieldDefinition == null) { Logger.Error(T("Impossible to find a field definition with name {0} within the part {1}.", criterion.FieldName, criterion.PartName).Text); } else { var propertyName = string.Join(".", // part criterion.PartName, // field criterion.FieldName, // field's property (e.g. LinkField.Text) criterion.PropertyName ?? ""); var fieldTypeEditors = GetFieldEditors(fieldDefinition.FieldDefinition.Name, criterion.PropertyName); if (fieldTypeEditors.Any()) { // I think there should be only one foreach (var fieldTypeEditor in fieldTypeEditors) { // use an alias with the join so that two filters on the same Field Type wont collide var relationship = fieldTypeEditor.GetFilterRelationship(propertyName.ToSafeName()); // generate the predicate based on the editor which has been used Action <IHqlExpressionFactory> predicate = y => y.Eq("PropertyName", propertyName); // apply a filter for the specific property context.Query = context.Query.Where(relationship, predicate); // apply sort context.Query = criterion.Ascending ? context.Query.OrderBy(relationship, x => x.Asc(context.GetSortColumnName())) : context.Query.OrderBy(relationship, x => x.Desc(context.GetSortColumnName())); } } else { Logger.Error(T("Impossible to identify the IFieldTypeEditor to sort by {0}.", propertyName).Text); } } } }
public void Activated() { foreach (var partName in _quickPartsManager.GetPartNames()) { var partDefinition = _contentDefinitionManager.GetPartDefinition(partName); if (partDefinition == null) { _contentDefinitionManager.AlterPartDefinition(partName, builder => builder.Attachable()); } } }
public async Task <ActionResult> EditPOST(string id, EditTypeViewModel viewModel) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContentTypes)) { return(Unauthorized()); } var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(id); if (contentTypeDefinition == null) { return(NotFound()); } viewModel.Settings = contentTypeDefinition.Settings; viewModel.TypeDefinition = contentTypeDefinition; viewModel.DisplayName = contentTypeDefinition.DisplayName; viewModel.Editor = await _contentDefinitionDisplayManager.UpdateTypeEditorAsync(contentTypeDefinition, this); if (!ModelState.IsValid) { _session.Cancel(); HackModelState(nameof(EditTypeViewModel.OrderedFieldNames)); HackModelState(nameof(EditTypeViewModel.OrderedPartNames)); return(View(viewModel)); } else { var ownedPartDefinition = _contentDefinitionManager.GetPartDefinition(contentTypeDefinition.Name); if (ownedPartDefinition != null && viewModel.OrderedFieldNames != null) { _contentDefinitionService.AlterPartFieldsOrder(ownedPartDefinition, viewModel.OrderedFieldNames); } _contentDefinitionService.AlterTypePartsOrder(contentTypeDefinition, viewModel.OrderedPartNames); _notifier.Success(T["\"{0}\" settings have been saved.", contentTypeDefinition.Name]); } return(RedirectToAction("Edit", new { id })); }
private EditRelationshipViewModel BuildEditorViewModel(TPrimaryPart part) { return(new EditRelationshipViewModel { Links = _primaryService.GetLinks(_entityName).Select(r => new SelectListItem() { Value = r.Id.ToString(), Text = _contentManager.GetItemMetadata(_contentManager.Get(r.Id)).DisplayText, }).ToList(), SelectedIds = GetLinks(part).Select(x => x.Id.ToString()).ToArray(), DisplayName = _contentDefinitionManager.GetPartDefinition(typeof(TPrimaryPart).Name).Settings["DisplayName"] }); }
private IEnumerable <int> GetIdsToProcess(HiddenStringFieldUpdateProcessVariant variant, ContentPartFieldDefinitionBuilder builder) { var partDefinition = _contentDefinitionManager.GetPartDefinition(builder.PartName); return(_contentManager.Query( _contentDefinitionManager.ListTypeDefinitions() .Where(td => td.Parts.Any(ptd => ptd.PartDefinition.Name == partDefinition.Name)) .Select(td => td.Name) .ToArray()) .List() .Where(ci => ci.Parts.Where(_partsEnumerableFilters[variant](builder)).Any()) .Select(ci => ci.Id)); }
private string[] GetLinkableTypesFromFieldDefinition(string part, string field) { var partFieldDefinition = _contentDefinitionManager.GetPartDefinition(part)?.Fields .FirstOrDefault(f => f.Name == field); var fieldSettings = partFieldDefinition?.GetSettings <BlockFieldSettings>(); if (fieldSettings == null) { throw new Exception("Unable to find field definition"); } return(fieldSettings.LinkableContentTypes); }
public async Task <IActionResult> SearchUsers(string part, string field, string contentType, string query) { if (string.IsNullOrWhiteSpace(part) || String.IsNullOrWhiteSpace(field) || string.IsNullOrWhiteSpace(contentType)) { return(BadRequest("Part, field and contentType are required parameters")); } var contentItem = await _contentManager.NewAsync(contentType); contentItem.Owner = User.FindFirstValue(ClaimTypes.NameIdentifier); if (!await _authorizationService.AuthorizeAsync(User, CommonPermissions.EditContent, contentItem)) { return(Forbid()); } var partFieldDefinition = _contentDefinitionManager.GetPartDefinition(part)?.Fields .FirstOrDefault(f => f.Name == field); var fieldSettings = partFieldDefinition?.GetSettings <UserPickerFieldSettings>(); if (fieldSettings == null) { return(BadRequest("Unable to find field definition")); } var editor = partFieldDefinition.Editor() ?? "Default"; var resultProvider = _resultProviders.FirstOrDefault(p => p.Name == editor) ?? _resultProviders.FirstOrDefault(p => p.Name == "Default"); if (resultProvider == null) { return(new ObjectResult(new List <UserPickerResult>())); } var results = await resultProvider.Search(new UserPickerSearchContext { Query = query, DisplayAllUsers = fieldSettings.DisplayAllUsers, Roles = fieldSettings.DisplayedRoles, PartFieldDefinition = partFieldDefinition }); return(new ObjectResult(results.Select(r => new VueMultiselectUserViewModel() { Id = r.UserId, DisplayText = r.DisplayText, IsEnabled = r.IsEnabled }))); }
public async Task <IActionResult> SearchLocalizationSets(string part, string field, string query) { if (string.IsNullOrWhiteSpace(part) || string.IsNullOrWhiteSpace(field)) { return(BadRequest("Part and field are required parameters")); } var partFieldDefinition = _contentDefinitionManager.GetPartDefinition(part)?.Fields .FirstOrDefault(f => f.Name == field); var fieldSettings = partFieldDefinition?.GetSettings <LocalizationSetContentPickerFieldSettings>(); if (fieldSettings == null) { return(BadRequest("Unable to find field definition")); } var dbQuery = _session.Query <ContentItem, ContentItemIndex>() .With <ContentItemIndex>(x => x.ContentType.IsIn(fieldSettings.DisplayedContentTypes) && x.Latest); if (!string.IsNullOrEmpty(query)) { dbQuery.With <ContentItemIndex>(x => x.DisplayText.Contains(query) || x.ContentType.Contains(query)); } var contentItems = await dbQuery.Take(40).ListAsync(); // if 2 search results have the same set, select one based on the current culture var cleanedContentItems = await _contentLocalizationManager.DeduplicateContentItemsAsync(contentItems); var results = new List <VueMultiselectItemViewModel>(); foreach (var contentItem in cleanedContentItems) { if (await _authorizationService.AuthorizeAsync(_httpContextAccessor.HttpContext.User, CommonPermissions.ViewContent, contentItem)) { results.Add(new VueMultiselectItemViewModel { Id = contentItem.Key, //localization set DisplayText = contentItem.Value.ToString(), HasPublished = await _contentManager.HasPublishedVersionAsync(contentItem.Value) }); } } return(new ObjectResult(results)); }
public async Task <ActionResult> EditPart(string id) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContentTypes)) { return(Forbid()); } var contentPartDefinition = _contentDefinitionManager.GetPartDefinition(id); if (contentPartDefinition == null) { return(NotFound()); } var viewModel = new EditPartViewModel(contentPartDefinition); viewModel.Editor = await _contentDefinitionDisplayManager.BuildPartEditorAsync(contentPartDefinition, _updateModelAccessor.ModelUpdater); return(View(viewModel)); }
public async Task <IActionResult> SearchContentItems(string part, string field, string query) { if (string.IsNullOrWhiteSpace(part) || String.IsNullOrWhiteSpace(field)) { return(BadRequest("Part and field are required parameters")); } var partFieldDefinition = _contentDefinitionManager.GetPartDefinition(part)?.Fields .FirstOrDefault(f => f.Name == field); var fieldSettings = partFieldDefinition?.GetSettings <ContentPickerFieldSettings>(); if (fieldSettings == null) { return(BadRequest("Unable to find field definition")); } var editor = partFieldDefinition.Editor() ?? "Default"; var resultProvider = _resultProviders.FirstOrDefault(p => p.Name == editor) ?? _resultProviders.FirstOrDefault(p => p.Name == "Default"); if (resultProvider == null) { return(new ObjectResult(new List <ContentPickerResult>())); } var results = await resultProvider.Search(new ContentPickerSearchContext { Query = query, DisplayAllContentTypes = fieldSettings.DisplayAllContentTypes, ContentTypes = fieldSettings.DisplayedContentTypes, PartFieldDefinition = partFieldDefinition }); return(new ObjectResult(results.Select(r => new VueMultiselectItemViewModel() { Id = r.ContentItemId, DisplayText = r.DisplayText, HasPublished = r.HasPublished }))); }
public void GetNavigation(NavigationBuilder builder) { var workContext = _workContextAccessor.GetContext(); var httpContext = workContext.HttpContext; if (httpContext == null) { return; } var queryString = workContext.HttpContext.Request.QueryString; string part = queryString["part"]; string field = queryString["field"]; ContentPickerSearchFieldSettings settings = null; // if the picker is loaded for a specific field, apply custom settings if (!String.IsNullOrEmpty(part) && !String.IsNullOrEmpty(field)) { var definition = _contentDefinitionManager.GetPartDefinition(part).Fields.FirstOrDefault(x => x.Name == field); if (definition != null) { settings = definition.Settings.GetModel <ContentPickerSearchFieldSettings>(); } } if (settings != null && !settings.ShowSearchTab) { return; } builder.Add(T("Content Picker"), menu => menu .Add(T("Search Content"), "5", item => item.Action("Index", "ContentPicker", new { area = "Orchard.Search" }).LocalNav())); }
public ActionResult EditFieldPOST(string id, EditFieldNameViewModel viewModel) { if (!Services.Authorizer.Authorize(Permissions.EditContentTypes, T("Not allowed to edit a content type."))) { return(new HttpUnauthorizedResult()); } if (viewModel == null) { return(HttpNotFound()); } var partViewModel = _contentDefinitionService.GetPart(id); if (partViewModel == null) { return(HttpNotFound()); } // prevent null reference exception in validation viewModel.DisplayName = viewModel.DisplayName ?? String.Empty; // remove extra spaces viewModel.DisplayName = viewModel.DisplayName.Trim(); if (String.IsNullOrWhiteSpace(viewModel.DisplayName)) { ModelState.AddModelError("DisplayName", T("The Display Name name can't be empty.").ToString()); } if (_contentDefinitionService.GetPart(partViewModel.Name).Fields.Any(t => t.Name != viewModel.Name && String.Equals(t.DisplayName.Trim(), viewModel.DisplayName.Trim(), StringComparison.OrdinalIgnoreCase))) { ModelState.AddModelError("DisplayName", T("A field with the same Display Name already exists.").ToString()); } if (!ModelState.IsValid) { return(View(viewModel)); } var field = _contentDefinitionManager.GetPartDefinition(id).Fields.FirstOrDefault(x => x.Name == viewModel.Name); if (field == null) { return(HttpNotFound()); } field.DisplayName = viewModel.DisplayName; _contentDefinitionManager.StorePartDefinition(partViewModel._Definition); Services.Notifier.Information(T("Display name changed to {0}.", viewModel.DisplayName)); // redirect to the type editor if a type exists with this name var typeViewModel = _contentDefinitionService.GetType(id); if (typeViewModel != null) { return(RedirectToAction("Edit", new { id })); } return(RedirectToAction("EditPart", new { id })); }