private static Tuple<INakedObjectAction, string>[] GetOverloadedActionsAndUIds(INakedObjectAction[] actions) { INakedObjectAction[] overloadedActions = actions.Where(a => actions.Count(ac => ac.Id == a.Id) > 1).ToArray(); if (overloadedActions.Any()) { return overloadedActions.Select(a => new Tuple<INakedObjectAction, string>(a, GetUniqueSuffix(a, actions))).ToArray(); } return new Tuple<INakedObjectAction, string>[] { }; }
public CollectionMemento(INakedObject target, INakedObjectAction action, INakedObject[] parameters) { Target = target; Action = action; Parameters = parameters; if (Target.Specification.IsViewModel) { PersistorUtils.PopulateViewModelKeys(Target); } }
internal ActionResult AppropriateView(ObjectAndControlData controlData, INakedObject nakedObject, INakedObjectAction action = null, string propertyName = null) { if (nakedObject == null) { // no object to go to // if action on object go to that object. // if action on collection go to collection // if action on service go to last object nakedObject = controlData.GetNakedObject(); if (nakedObject.Specification.IsService) { object lastObject = Session.LastObject(ObjectCache.ObjectFlag.BreadCrumb); if (lastObject == null) { TempData[IdHelper.NofMessages] = NakedObjectsContext.MessageBroker.Messages; TempData[IdHelper.NofWarnings] = NakedObjectsContext.MessageBroker.Warnings; return RedirectToAction(IdHelper.IndexAction, IdHelper.HomeName); } nakedObject = FrameworkHelper.GetNakedObject(lastObject); } } if (nakedObject.Specification.IsCollection && !nakedObject.Specification.IsParseable) { var collection = nakedObject.GetAsQueryable(); int collectionSize = collection.Count(); if (collectionSize == 1) { // remove any paging data - to catch case where custom page has embedded standalone collection as paging data will confuse rendering ViewData.Remove(IdHelper.PagingData); return View("ObjectView", collection.First()); } nakedObject = Page(nakedObject, collectionSize, controlData, nakedObject.IsNotQueryable()); action = action ?? ((CollectionMemento)nakedObject.Oid).Action; int page, pageSize; CurrentlyPaging(controlData, collectionSize, out page, out pageSize); var format = ViewData["NofCollectionFormat"] as string; return View("StandaloneTable", ActionResultModel.Create(action, nakedObject, page, pageSize, format)); } // remove any paging data - to catch case where custom page has embedded standalone collection as paging data will confuse rendering ViewData.Remove(IdHelper.PagingData); if (controlData.DataDict.Values.Contains("max")) { // maximizing an inline object - do not update history ViewData.Add("updateHistory", false); } return propertyName == null ? View(nakedObject.IsNotPersistent() ? "ObjectView" : "ViewNameSetAfterTransaction", nakedObject.Object) : View(nakedObject.IsNotPersistent() ? "PropertyView" : "ViewNameSetAfterTransaction", new PropertyViewModel(nakedObject.Object, propertyName)); }
private static string GetUniqueSuffix(INakedObjectAction action, INakedObjectAction[] actions) { INakedObjectAction[] overloadedActions = actions.Where(a => a.Id == action.Id && actions.Count(ac => ac.Id == a.Id) > 1).ToArray(); if (overloadedActions.Any()) { var actionAndParms = overloadedActions.Select(a => new Tuple<INakedObjectAction, string>(a, ((Func<INakedObjectAction, string>)(act => act.Parameters.Aggregate("", (acc, p) => a + p.Id + p.Specification.FullName)))(a))); int index = 0; var orderedActions = actionAndParms.OrderBy(ap => ap.Item2).Select(ap => ap.Item1).ToDictionary(a => a, a => index++); var suffix = orderedActions[action].ToString(); while (actions.Select(a => a.Id).Contains(action.Id + suffix)) { suffix = "0" + suffix; } return suffix; } return ""; }
internal void SetDefaults(INakedObject nakedObject, INakedObjectAction action) { foreach (INakedObjectActionParameter parm in action.Parameters) { INakedObject value = parm.GetDefault(nakedObject); TypeOfDefaultValue typeOfValue = parm.GetDefaultType(nakedObject); bool ignore = value == null || (value.Object is DateTime && ((DateTime) value.Object).Ticks == 0) || typeOfValue == TypeOfDefaultValue.Implicit; if (!ignore) { // deliberately not an attempted value so it only gets populated after masking ViewData[IdHelper.GetParameterInputId(action, parm)] = parm.Specification.IsParseable ? value.Object : value; } } }
internal IEnumerable<INakedObject> GetParameterValues(INakedObjectAction action, ObjectAndControlData controlData) { return action.Parameters.Select(parm => GetParameterValue(parm, IdHelper.GetParameterInputId(action, parm), controlData)); }
internal void SetContextObjectAsParameterValue(INakedObjectAction targetAction, INakedObject contextNakedObject) { if (targetAction.Parameters.Any(p => p.Specification.IsOfType(contextNakedObject.Specification))) { foreach (INakedObjectActionParameter parm in targetAction.Parameters) { if (parm.Specification.IsOfType(contextNakedObject.Specification)) { string name = IdHelper.GetParameterInputId(targetAction, parm); AddAttemptedValue(name, contextNakedObject); } } } }
public static string GetParameterAutoCompleteId(INakedObjectAction action, INakedObjectActionParameter parameter) { var id = GetParameterInputId(action, parameter); return parameter.Specification.IsParseable ? id : id + sep + autoCompleteName; }
public void ValidateParameter(INakedObjectAction action, INakedObjectActionParameter parm, INakedObject targetNakedObject, INakedObject valueNakedObject) { IConsent consent = parm.IsValid(targetNakedObject, valueNakedObject); if (!consent.IsAllowed) { ModelState.AddModelError(IdHelper.GetParameterInputId(action, parm), consent.Reason); } }
public NakedObjectActionParameterParseable(int index, INakedObjectAction action, INakedObjectActionParamPeer peer) : base(index, action, peer) {}
public void SetupAction(INakedObjectAction action) { this.action = action; }
internal void SetSelectedParameters(INakedObjectAction action) { var refItems = action.Parameters.Where(p => p.IsObject && !p.Specification.IsParseable).Where(p => ValueProvider.GetValue(p.Id) != null).ToList(); if (refItems.Any()) { Dictionary<string, INakedObject> items = refItems.ToDictionary(p => IdHelper.GetParameterInputId(action, p), p => FrameworkHelper.GetNakedObjectFromId(ValueProvider.GetValue(p.Id).AttemptedValue)); items.ForEach(kvp => ViewData[kvp.Key] = kvp.Value); } }
internal static bool ActionExecutingAsContributed(INakedObjectAction action, INakedObject targetNakedObject) { return action.IsContributedMethod && action.OnType != targetNakedObject.Specification; }
public ActionContext(bool embeddedInObject, object target, INakedObjectAction action) : base(target) { EmbeddedInObject = embeddedInObject; Action = action; }
public ParameterContext(bool embeddedInObject, object target, INakedObjectAction action, INakedObjectActionParameter parameter, bool isEdit) : base(embeddedInObject, target, action) { Parameter = parameter; IsParameterEdit = isEdit; }
public ActionContext(object target, INakedObjectAction action) : base(target) { EmbeddedInObject = false; Action = action; }
private IDictionary<string, INakedObject> GetOtherValues(INakedObjectAction action) { var results = new Dictionary<string, INakedObject>(); var parms = new FormCollection(HttpContext.Request.Params); Decrypt(parms); foreach (INakedObjectActionParameter parm in action.Parameters) { string[] values = GetRawValues(parms, IdHelper.GetParameterInputId(action, parm)); results[parm.Id.ToLower()] = GetValue(values, parm.Specification); } return results; }
public OneToManyActionParameterImpl(int index, INakedObjectAction actionImpl, INakedObjectActionParamPeer peer) : base(index, actionImpl, peer) {}
public TestAction(string contributor, INakedObjectAction action, ITestHasActions owningObject, ITestObjectFactory factory) { SubMenu = contributor; this.owningObject = owningObject; this.factory = factory; this.action = action; }
public TestAction(INakedObjectAction action, ITestHasActions owningObject, ITestObjectFactory factory) : this(string.Empty, action, owningObject, factory) {}
internal void SetSelectedParameters(INakedObject nakedObject, INakedObjectAction action, IDictionary<string, string> dict) { var refItems = action.Parameters.Where(p => p.IsObject && !p.Specification.IsParseable).Where(p => dict.ContainsKey(p.Id)).ToList(); if (refItems.Any()) { refItems.ForEach(p => ValidateParameter(action, p, nakedObject, FrameworkHelper.GetNakedObjectFromId(dict[p.Id]))); Dictionary<string, INakedObject> items = refItems.ToDictionary(p => IdHelper.GetParameterInputId(action, p), p => FrameworkHelper.GetNakedObjectFromId(dict[p.Id])); items.ForEach(kvp => ViewData[kvp.Key] = kvp.Value); } }
public INakedObjectAction GetAction() { if (nakedObjectAction == null) { nakedObjectAction = FrameworkHelper.GetActions(GetNakedObject()).SingleOrDefault(a => a.Id == ActionId); } return nakedObjectAction; }
public ITestAction CreateTestAction(string contributor, INakedObjectAction action, ITestHasActions owningObject) { return new TestAction(contributor, action, owningObject, this); }
public static string GetParameterContainerId(INakedObjectAction action) { return action.Id + sep + ParamListName; }
public ITestAction CreateTestAction(INakedObjectAction action, ITestHasActions owningObject) { return new TestAction(action, owningObject, this); }
public static string GetOverloadedUId(INakedObjectAction action, INakedObjectSpecification spec) { INakedObjectAction[] actions = spec.GetActionLeafNodes(); Tuple<INakedObjectAction, string>[] overloadedActions = GetOverloadedActionsAndUIds(actions); return overloadedActions.Where(oa => oa.Item1 == action).Select(oa => oa.Item2).SingleOrDefault(); }
public ITestParameter CreateTestParameter(INakedObjectAction action, INakedObjectActionParameter parameter, ITestHasActions owningObject) { return new TestParameter(action, parameter, owningObject, this); }
public NakedObjectActionWrapper(INakedObjectAction action, INakedObjectsSurface surface, string overloadedUniqueId) { this.action = action; this.overloadedUniqueId = overloadedUniqueId; Surface = surface; }
public TestParameter(INakedObjectAction action, INakedObjectActionParameter parameter, ITestHasActions owningObject, ITestObjectFactory factory) { this.action = action; this.parameter = parameter; this.owningObject = owningObject; this.factory = factory; }
internal bool ValidateParameters(INakedObject targetNakedObject, INakedObjectAction action, ObjectAndControlData controlData) { // check mandatory fields first to emulate WPF UI behaviour where no validation takes place until // all mandatory fields are set. foreach (INakedObjectActionParameter parm in action.Parameters) { object result = GetRawParameterValue(parm, controlData, IdHelper.GetParameterInputId(action, parm)); var stringResult = result as string; if (parm.IsMandatory && (result == null || (result is string && string.IsNullOrEmpty(stringResult)))) { ModelState.AddModelError(IdHelper.GetParameterInputId(action, parm), MvcUi.Mandatory); } } //check for individual parameter validity, including parsing of text input if (ModelState.IsValid) { foreach (INakedObjectActionParameter parm in action.Parameters) { try { INakedObject valueNakedObject = GetParameterValue(parm, IdHelper.GetParameterInputId(action, parm), controlData); ValidateParameter(action, parm, targetNakedObject, valueNakedObject); } catch (InvalidEntryException) { ModelState.AddModelError(IdHelper.GetParameterInputId(action, parm), MvcUi.InvalidEntry); } } } // check for validity of whole set, including any 'co-validation' involving multiple parameters if (ModelState.IsValid) { IEnumerable<INakedObject> parms = action.Parameters.Select(p => GetParameterValue(p, IdHelper.GetParameterInputId(action, p), controlData)); IConsent consent = action.IsParameterSetValid(targetNakedObject, parms.ToArray()); if (!consent.IsAllowed) { ModelState.AddModelError(string.Empty, consent.Reason); } } return ModelState.IsValid; }