protected override FurtherValidationResult Validate(ContentModifierForm form, ContentFieldValidatorConfiguration config, ContentType contentType, ContentFieldDefinition fieldDefinition) { var fm = form.DirectCastTo <FilePickerFieldModifierForm>(); var cfg = config.DirectCastTo <FileExtensionValidatorConfiguration>(); if (cfg.AllowedFileExtensions.Length == 0) { return(null); } var errs = new List <string>(); var allowedFileExts = cfg.AllowedFileExtensions.Where(x => x?.Trim().Trim('.').ToLowerInvariant() != null).ToArray(); var isOrAre = allowedFileExts.Length > 0 ? "are" : "is"; var allowedFileExtsStr = $"'{string.Join("', '", allowedFileExts)}'"; foreach (var path in fm.Val) { var lastDotIdx = path.LastIndexOf('.'); var fileExt = path.Substring(lastDotIdx).Trim('.'); if (allowedFileExts.All(x => x != fileExt.ToLowerInvariant())) { errs.Add($"File extension '{fileExt}' is not allowed. Only {allowedFileExtsStr} {isOrAre} allowed."); } } if (errs.Count == 0) { return(null); } var valres = new FurtherValidationResult(); valres.Errors[nameof(FilePickerFieldModifierForm.Val)] = errs.ToArray(); return(valres); }
public string GenerateFauxUrlSlugPart(string param, ContentFieldDefinition fieldDef) { if (!Val.HasValue) { return(null); } var fcfg = fieldDef.Config.DirectCastTo <ChronoFieldConfiguration>(); var dt = fcfg.Kind == DateTimeKind.Utc ? ValAsUtcDateTime.Value : ValAsLocalDateTime.Value; switch (param) { case "year": return(dt.ToString("yyyy")); case "month": return(dt.ToString("MM")); case "date": return(dt.ToString("dd")); case "hour": return(dt.ToString("HH")); case "minute": return(dt.ToString("mm")); case "second": return(dt.ToString("ss")); } return(dt.ToString("yyyy-MM-dd-HH-mm-ss")); }
public void PerformModification(ContentModifierForm modifierForm, ContentField field, ContentModifyOperation operation, ProtoContent content, ContentFieldDefinition fieldDefinition) { var fm = modifierForm.DirectCastTo <FilePickerFieldModifierForm>(); var fnPrefix = $"{fieldDefinition.FieldName}.{nameof(FilePickerField.Val)}."; var existing = content.ContentFields.Where(x => x.FieldName.StartsWith(fnPrefix)).ToArray(); foreach (var cfe in existing) { content.ContentFields.Remove(cfe); _dbContext.ProtoFields.Remove(cfe); } var idx = 0; foreach (var path in fm.Val) { var cf = new ProtoField { ContentId = content.Id, StringValue = path, FieldName = $"{fnPrefix}{idx}", FieldClassTypeName = typeof(FilePickerField).FullName }; content.ContentFields.Add(cf); idx++; } }
public ActionResult EditFields(string id, string fieldName) { if (!Services.Authorizer.Authorize(Permissions.EditContentTypes, T("Not allowed to edit a content type."))) { return(new HttpUnauthorizedResult()); } var entity = _contentMetadataService.GetEntity(id); if (entity == null) { return(HttpNotFound()); } var field = entity.FieldMetadataRecords.FirstOrDefault(x => x.Name == fieldName); if (field == null) { return(HttpNotFound()); } var settings = _contentMetadataService.ParseSetting(field.Settings); var fieldDefinition = new ContentFieldDefinition(field.ContentFieldDefinitionRecord.Name); var viewModel = new EditPartFieldViewModel { Name = field.Name, DisplayName = settings["DisplayName"], Settings = settings, FieldDefinition = new EditFieldViewModel(fieldDefinition), Templates = _contentDefinitionEditorEvents.PartFieldEditor(new ContentPartFieldDefinition(fieldDefinition, field.Name, settings)) }; return(View(viewModel)); }
protected override FurtherValidationResult Validate(ContentModifierForm form, ContentFieldValidatorConfiguration config, ContentType contentType, ContentFieldDefinition fieldDefinition) { var valCfg = config.DirectCastTo <TextFieldLengthValidatorConfiguration>(); var f = form.DirectCastTo <TextFieldModifierForm>(); if (f.Val == null) { return(null); } var result = new FurtherValidationResult(); var dispName = fieldDefinition.Config.Label ?? fieldDefinition.FieldName; if (valCfg.MinLength.HasValue) { var ml = valCfg.MinLength.Value; if (f.Val.Length < ml) { result.AddError(nameof(f.Val), string.Format(valCfg.MinLengthErrorMessage, dispName, ml)); } } if (valCfg.MaxLength.HasValue) { var ml = valCfg.MaxLength.Value; if (f.Val.Length > ml) { result.AddError(nameof(f.Val), string.Format(valCfg.MaxLengthErrorMessage, dispName, ml)); } } return(result); }
public void PerformModification(ContentModifierForm modifierForm, ContentField field, ContentModifyOperation operation, ProtoContent content, ContentFieldDefinition fieldDefinition) { var f = modifierForm.DirectCastTo <SelectFieldModifierForm>(); var fnPrefix = $"{fieldDefinition.FieldName}.{nameof(SelectField.Val)}."; var existingCfs = content.ContentFields.Where(x => x.FieldName.StartsWith(fnPrefix)) .ToArray(); foreach (var excf in existingCfs) { content.ContentFields.Remove(excf); _dbContext.ProtoFields.Remove(excf); } var idx = 0; foreach (var fv in f.Val) { if (fv == null) { continue; } var cf = new ProtoField { ContentId = content.Id, FieldName = $"{fnPrefix}{idx}" }; content.ContentFields.Add(cf); cf.FieldClassTypeName = typeof(SelectField).FullName; cf.StringValue = fv; idx++; } }
public VueComponentDefinition[] ConvertFormToVues(ContentModifierForm modifierForm, ContentField field, ContentModifyOperation operation, ProtoContent content, ContentFieldDefinition fieldDefinition) { var vues = new List <VueComponentDefinition>(); if (operation.IsDeleteOperation()) { vues.Add(new VueHtmlWidget("Proceed to delete?")); } vues.AddRange(new[] { new VueComponentDefinition { Name = "cms-form-field-hidden", Props = new { valuePath = nameof(CommonFieldModifierForm.ContentId) } }, new VueComponentDefinition { Name = "cms-form-field-hidden", Props = new { valuePath = nameof(CommonFieldModifierForm.ContentTypeId) } }, new VueComponentDefinition { Name = "cms-form-field-hidden", Props = new { valuePath = nameof(CommonFieldModifierForm.OperationName) } } }); return(vues.ToArray()); }
public FieldConfigurerImpl(ContentPartFieldDefinition field, ContentPartDefinition part) : base(field) { _fieldDefinition = field.FieldDefinition; _fieldName = field.Name; _partDefinition = part; }
public ContentField GetModel(ProtoContent content, ContentFieldDefinition fieldDefinition) { var mdl = new TrashingField(); var tfn = $"{fieldDefinition.FieldName}.{nameof(TrashingField.TrashedUtc)}"; mdl.TrashedUtc = content.ContentFields.FirstOrDefault(x => x.FieldName == tfn)?.DateTimeValue; return(mdl); }
public string GenerateFauxUrlSlugPart(string param, ContentFieldDefinition fieldDefinition) { if (string.IsNullOrWhiteSpace(Val)) { return(null); } return(param == "lowercase" ? Val.ToUrlSlug().ToLowerInvariant() : Val.ToUrlSlug()); }
public Expression <Func <ProtoContent, bool> > Search(string keywords, string[] splittedKeywords, ContentFieldDefinition fieldDefinition) { var fnPrefix = $"{fieldDefinition.FieldName}.{nameof(SelectField.Val)}."; return(x => splittedKeywords.Any(k => x.ContentFields.Any(cf => cf.FieldName.StartsWith(fnPrefix) && cf.StringValue.Contains(k)))); }
private VueComponentDefinition[] FullPreviewValue(ContentField field, ContentFieldDefinition definition) { var f = field.DirectCastTo <FauxUrlSlugField>(); var fullUrl = GetFullUrl(f); return(new VueComponentDefinition[] { new VueHtmlWidget($"<a href='{fullUrl}' target='_blank'>{fullUrl}</a>") }); }
public ContentField GetModel(ProtoContent content, ContentFieldDefinition fieldDefinition) { var mdl = new BooleanField(); var fn = $"{fieldDefinition.FieldName}.{nameof(BooleanField.Val)}"; var f = content.ContentFields.FirstOrDefault(x => x.FieldName == fn); mdl.Val = f?.BooleanValue; return(mdl); }
public IQueryable <ProtoContent> Sort(IQueryable <ProtoContent> currentQuery, string sortFieldName, bool isDescending, ContentFieldDefinition fieldDefinition) { var fnPrefix = $"{fieldDefinition.FieldName}.{nameof(FilePickerField.Val)}."; return(currentQuery.AddOrderBy(x => x.ContentFields.FirstOrDefault(cf => cf.FieldName.StartsWith(fnPrefix)).StringValue)); }
public ContentField GetModel(ProtoContent content, ContentFieldDefinition fieldDefinition) { var mdl = new TextField(); var fn = $"{fieldDefinition.FieldName}.{nameof(TextField.Val)}"; var cf = content.ContentFields.FirstOrDefault(x => x.FieldName == fn); mdl.Val = cf?.StringValue; return(mdl); }
public ContentField GetModel(ProtoContent content, ContentFieldDefinition fieldDefinition) { var mdl = new FauxUrlSlugField(); var ct = fieldDefinition.ContentType; var fcfg = fieldDefinition.Config.DirectCastTo <FauxUrlSlugFieldConfiguration>(); var slugPatternParts = fcfg.SlugPattern.Trim('/').Split('/'); var slugParts = new List <string>(); foreach (var spp in slugPatternParts) { if (spp == ID_PATTERN_PART) { var cid = content.Id.Replace("-", ""); var pt = cid.Length <= fcfg.ContentIdSlugPartLength ? cid : cid.Substring(0, fcfg.ContentIdSlugPartLength); if (!string.IsNullOrWhiteSpace(pt)) { slugParts.Add(pt); } continue; } var matchSimple = PartPatternSimpleRegex.Match(spp); if (matchSimple.Success) { var fieldName = matchSimple.Groups["fieldName"].Value; var slugGenFieldDef = ct.Fields.First(x => x.FieldName == fieldName); var slugGenField = slugGenFieldDef.FieldFinder().GetModel(content, slugGenFieldDef) .DirectCastTo <IFauxUrlSlugGenerator>(); var pt = slugGenField?.GenerateFauxUrlSlugPart(null, slugGenFieldDef); if (!string.IsNullOrWhiteSpace(pt)) { slugParts.Add(pt); } continue; } var matchComplex = PartPatternComplexRegex.Match(spp); if (matchComplex.Success) { var fieldName = matchComplex.Groups["fieldName"].Value; var slugGenFieldDef = ct.Fields.First(x => x.FieldName == fieldName); var slugGenField = slugGenFieldDef.FieldFinder().GetModel(content, slugGenFieldDef) .DirectCastTo <IFauxUrlSlugGenerator>(); var slugGenParam = matchComplex.Groups["slugGeneratorParam"].Value; var pt = slugGenField?.GenerateFauxUrlSlugPart(slugGenParam, slugGenFieldDef); if (!string.IsNullOrWhiteSpace(pt)) { slugParts.Add(pt); } continue; } slugParts.Add(spp); } mdl.Slug = string.Join("/", slugParts); return(mdl); }
protected override FurtherValidationResult Validate(ContentModifierForm form, ContentFieldValidatorConfiguration config, ContentType contentType, ContentFieldDefinition fieldDefinition) { var f = form.DirectCastTo <NumberFieldModifierForm>(); var valCfg = config.DirectCastTo <NumberFieldRangeValidatorConfiguration>(); if (!f.Val.HasValue) { return(null); } var result = new FurtherValidationResult(); var dispName = fieldDefinition.Config.Label ?? fieldDefinition.FieldName; if (valCfg.MinValue.HasValue) { var mv = valCfg.MinValue.Value; if (valCfg.MinValueIsInclusive) { if (f.Val.Value < mv) { result.AddError( nameof(f.Val), string.Format(valCfg.MinValueInclusiveErrorMessage, dispName, mv)); } } else { if (f.Val.Value <= mv) { result.AddError( nameof(f.Val), string.Format(valCfg.MinValueErrorMessage, dispName, mv)); } } } if (valCfg.MaxValue.HasValue) { var mv = valCfg.MaxValue.Value; if (valCfg.MaxValueIsInclusive) { if (f.Val.Value > mv) { result.AddError( nameof(f.Val), string.Format(valCfg.MaxValueInclusiveErrorMessage, dispName, mv)); } } else { if (f.Val.Value >= mv) { result.AddError( nameof(f.Val), string.Format(valCfg.MaxValueErrorMessage, dispName, mv)); } } } return(result); }
private string GetSummaryValue(ContentField field, ContentFieldDefinition definition) { var f = field.DirectCastTo <TextField>(); var cfg = definition.Config.DirectCastTo <TextFieldConfiguration>(); var stripped = f.Val.StripHtmlTags(); var shortened = stripped == null ? "" : (stripped.Length > cfg.MaxSummaryLength ? stripped.Substring(0, cfg.MaxSummaryLength) + "..." : stripped); return(shortened); }
public ContentModifierForm BuildModifierForm(ContentField field, ContentModifyOperation operation, ProtoContent content, ContentFieldDefinition fieldDefinition) { var fi = field.DirectCastTo <FilePickerField>(); var fm = new FilePickerFieldModifierForm { Val = fi.Val }; return(fm); }
public Expression <Func <ProtoContent, bool> > Search(string keywords, string[] splittedKeywords, ContentFieldDefinition fieldDefinition) { var fcfg = fieldDefinition.Config.DirectCastTo <FauxUrlSlugFieldConfiguration>(); var idLen = fcfg.ContentIdSlugPartLength; return(c => splittedKeywords.Any( k => c.Id.Replace("-", "").Length >= idLen && c.Id.Replace("-", "").Substring(0, idLen).Contains(k) || c.Id.Replace("-", "").Contains(k) )); }
private string SummarizedValueForWeb(ContentField contentField, ContentFieldDefinition contentFieldDefinition) { var fi = contentField.DirectCastTo <FilePickerField>(); var fcfg = contentFieldDefinition.Config.DirectCastTo <FilePickerFieldConfiguration>(); if (fcfg.IsMultiSelect) { return($"{fi.WebPaths.Length} file{(fi.WebPaths.Length > 1 ? "s" : "")}"); } return(fi.WebPaths.FirstOrDefault()); }
public Expression <Func <ProtoContent, bool> > Search(string keywords, string[] splittedKeywords, ContentFieldDefinition fieldDefinition) { var fn = $"{fieldDefinition.FieldName}.{nameof(TextField.Val)}"; Expression <Func <ProtoContent, bool> > expr = x => x.ContentFields.Any(cf => cf.FieldName == fn && splittedKeywords.Any( k => cf.StringValue.Contains(k) ) ); return(expr); }
public ContentModifierForm BuildModifierForm(ContentField field, ContentModifyOperation operation, ProtoContent content, ContentFieldDefinition fieldDefinition) { var cf = field.DirectCastTo <SelectField>(); var val = cf.Val; var form = new SelectFieldModifierForm { Val = val }; return(form); }
public ContentModifierForm BuildModifierForm(ContentField field, ContentModifyOperation operation, ProtoContent content, ContentFieldDefinition fieldDefinition) { var f = new CommonFieldModifierForm { ContentId = content?.Id, ContentTypeId = content?.ContentTypeId, OperationName = operation.Name }; return(f); }
public ContentModifierForm BuildModifierForm(ContentField field, ContentModifyOperation operation, ProtoContent content, ContentFieldDefinition fieldDefinition) { var f = field != null?field.DirectCastTo <PublishingField>() : new PublishingField(); var form = new PublishingFieldModifierForm { PublishedAt = f.PublishedUtc?.ToLocalTime(), UnpublishedAt = f.UnpublishedUtc?.ToLocalTime() }; return(form); }
private ContentFieldDefinitionRecord Acquire(ContentFieldDefinition contentFieldDefinition) { var result = GetContentDefinitionRecord().ContentFieldDefinitionRecords.SingleOrDefault(x => x.Name == contentFieldDefinition.Name); if (result == null) { result = new ContentFieldDefinitionRecord { Name = contentFieldDefinition.Name }; GetContentDefinitionRecord().ContentFieldDefinitionRecords.Add(result); } return(result); }
private ContentFieldDefinitionRecord Acquire(ContentFieldDefinition contentFieldDefinition) { var result = _fieldDefinitionRepository.Table.SingleOrDefault(x => x.Name == contentFieldDefinition.Name); if (result == null) { result = new ContentFieldDefinitionRecord { Name = contentFieldDefinition.Name }; _fieldDefinitionRepository.Create(result); } return(result); }
public ContentField GetModel(ProtoContent content, ContentFieldDefinition fieldDefinition) { var mdl = new ChronoField(); var fn = $"{fieldDefinition.FieldName}.{nameof(ChronoField.Val)}"; mdl.Val = content.ContentFields.FirstOrDefault(x => x.FieldName == fn)?.DateTimeValue; var cfg = fieldDefinition.Config.DirectCastTo <ChronoFieldConfiguration>(); if (mdl.Val.HasValue) { mdl.Val = DateTime.SpecifyKind(mdl.Val.Value, cfg.Kind); } return(mdl); }
public ContentField GetModel(ProtoContent content, ContentFieldDefinition fieldDefinition) { var model = new CommonField { Id = content.Id, ContentTypeId = content.ContentTypeId, CreatedUtc = content.CreatedUtc, UpdatedUtc = content.UpdatedUtc, CreatedByUserId = content.CreatedByUserId, CreatedByUserName = content.CreatedByUserName, CreatedByUserDisplayName = content.CreatedByUserDisplayName }; return(model); }
public IQueryable <ProtoContent> Sort(IQueryable <ProtoContent> currentQuery, string sortFieldName, bool isDescending, ContentFieldDefinition fieldDefinition) { var q = currentQuery; var fn = $"{fieldDefinition.FieldName}.{nameof(ChronoField.Val)}"; if (sortFieldName == fieldDefinition.FieldName || sortFieldName == fn) { q = q.AddOrderBy(c => c.ContentFields.FirstOrDefault(x => x.FieldName == fn).DateTimeValue, isDescending); } return(q); }
public abstract ContentPartFieldDefinitionBuilder OfType(ContentFieldDefinition fieldDefinition);
public ContentPartFieldDefinition( ContentFieldDefinition contentFieldDefinition, string name, SettingsDictionary settings) { Name = name; FieldDefinition = contentFieldDefinition; Settings = settings; }
private ContentFieldDefinitionRecord Acquire(ContentFieldDefinition contentFieldDefinition) { var result = _fieldDefinitionRepository.Table.SingleOrDefault(x => x.Name == contentFieldDefinition.Name); if (result == null) { result = new ContentFieldDefinitionRecord { Name = contentFieldDefinition.Name }; _fieldDefinitionRepository.Create(result); } return result; }
public FieldConfigurerImpl(ContentPartFieldDefinition field) : base(field) { _fieldDefinition = field.FieldDefinition; _fieldName = field.Name; }
public override ContentPartFieldDefinitionBuilder OfType(ContentFieldDefinition fieldDefinition) { _fieldDefinition = fieldDefinition; return this; }
public override ContentPartFieldDefinitionBuilder OfType(string fieldType) { _fieldDefinition = new ContentFieldDefinition(fieldType); return this; }
public ContentPartFieldDefinition(string name) { Name = name; FieldDefinition = new ContentFieldDefinition(null); Settings = new SettingsDictionary(); }