protected override DriverResult Editor(ContentPart part, OptionSetField field, dynamic shapeHelper) { return(ContentShape("Fields_OptionSetField_Edit", GetDifferentiator(field, part), () => { var settings = field.PartFieldDefinition.Settings.GetModel <OptionSetFieldSettings>(); var appliedTerms = _optionSetService.GetOptionItemsForContentItem(part.ContentItem.Id, field.Name).Distinct(new TermPartComparer()).ToDictionary(t => t.Id, t => t); var optionSet = _optionSetService.GetOptionSet(settings.OptionSetId); var optionItems = optionSet != null ? _optionSetService.GetOptionItems(optionSet.Id).Where(t => !string.IsNullOrWhiteSpace(t.Name)).Select(t => t.CreateTermEntry()).ToList() : new List <OptionItemEntry>(0); optionItems.ForEach(t => t.IsChecked = appliedTerms.ContainsKey(t.Id)); var viewModel = new OptionSetFieldViewModel { Name = field.Name, DisplayName = field.DisplayName, OptionItems = optionItems, Settings = settings, SingleTermId = optionItems.Where(t => t.IsChecked).Select(t => t.Id).FirstOrDefault(), OptionSetId = optionSet != null ? optionSet.Id : 0 }; return shapeHelper.EditorTemplate(TemplateName: "Fields/OptionSetField", Model: viewModel, Prefix: GetPrefix(field, part)); })); }
// 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); }
protected override DriverResult Display(OptionSetPart part, string displayType, dynamic shapeHelper) { return(ContentShape("Parts_OptionSetPart", () => { var taxonomyShape = shapeHelper.Taxonomy(ContentPart: part, ContentItem: part.ContentItem); var terms = _optionSetService.GetOptionItems(part.ContentItem.Id); return shapeHelper.Parts_OptionSetPart(Taxonomy: taxonomyShape); })); }
// GET api/<controller> public object Get(int optionSetId, int page, int rows) { var result = _optionSetService.GetOptionItems(optionSetId); if (!result.Any()) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } var query = result.Select(part => part.CreateTermEntry()); var totalRecords = query.Count(); return(new { total = Convert.ToInt32(Math.Ceiling((double)totalRecords / rows)), page = page, records = totalRecords, rows = query }); }
public OptionSetPartHandler( IRepository<OptionSetPartRecord> repository, IOptionSetService optionSetService, IContentDefinitionManager contentDefinitionManager) { int? previousId = null; Filters.Add(StorageFilter.For(repository)); OnPublished<OptionSetPart>((context, part) => { var previousTermTypeName = part.TermTypeName; if (previousId != null && part.Id != previousId) { // remove previous term type contentDefinitionManager.DeleteTypeDefinition(previousTermTypeName); // update existing fields foreach (var partDefinition in contentDefinitionManager.ListPartDefinitions()) { foreach (var field in partDefinition.Fields) { if (field.FieldDefinition.Name == typeof (OptionSetField).Name) { if (field.Settings.GetModel<OptionSetFieldSettings>().OptionSetId == previousId) { contentDefinitionManager.AlterPartDefinition(partDefinition.Name, cfg => cfg.WithField(field.Name, builder => builder.WithSetting("TaxonomyFieldSettings.TaxonomyId", part.Id.ToString()))); } } } } } }); OnLoading<OptionSetPart>((context, part) => part.OptionItemsField.Loader(x => optionSetService.GetOptionItems(part.Id))); OnUpdating<TitlePart>((context, part) => { // if altering the title of a taxonomy, save the name if (part.As<OptionSetPart>() != null) { previousId = part.Id; } }); }
public OptionSetPartHandler( IRepository <OptionSetPartRecord> repository, IOptionSetService optionSetService, IContentDefinitionManager contentDefinitionManager) { int?previousId = null; Filters.Add(StorageFilter.For(repository)); OnPublished <OptionSetPart>((context, part) => { var previousTermTypeName = part.TermTypeName; if (previousId != null && part.Id != previousId) { // remove previous term type contentDefinitionManager.DeleteTypeDefinition(previousTermTypeName); // update existing fields foreach (var partDefinition in contentDefinitionManager.ListPartDefinitions()) { foreach (var field in partDefinition.Fields) { if (field.FieldDefinition.Name == typeof(OptionSetField).Name) { if (field.Settings.GetModel <OptionSetFieldSettings>().OptionSetId == previousId) { contentDefinitionManager.AlterPartDefinition(partDefinition.Name, cfg => cfg.WithField(field.Name, builder => builder.WithSetting("TaxonomyFieldSettings.TaxonomyId", part.Id.ToString()))); } } } } } }); OnLoading <OptionSetPart>((context, part) => part.OptionItemsField.Loader(x => optionSetService.GetOptionItems(part.Id))); OnUpdating <TitlePart>((context, part) => { // if altering the title of a taxonomy, save the name if (part.As <OptionSetPart>() != null) { previousId = part.Id; } }); }