protected ListRepresentation(IOidStrategy oidStrategy, IObjectFacade list, HttpRequestMessage req, RestControlFlags flags, ActionContextFacade actionContext)
            : base(oidStrategy, flags) {
            Value = list.ToEnumerable().Select(no => CreateObjectLink(oidStrategy, req, no, actionContext)).ToArray();

            SetLinks(req, actionContext);
            SetExtensions(oidStrategy, actionContext);
            SetHeader(false);
        }
Esempio n. 2
0
 private static object CreateDefaultLinks(IOidStrategy oidStrategy, HttpRequestMessage req, FieldFacadeAdapter parameter, IActionFacade action, IObjectFacade defaultNakedObject, string title, RestControlFlags flags)
 {
     if (defaultNakedObject.Specification.IsCollection)
     {
         return(defaultNakedObject.ToEnumerable().Select(i => CreateDefaultLink(oidStrategy, req, parameter, action, i, i.TitleString, flags)).ToArray());
     }
     return(CreateDefaultLink(oidStrategy, req, parameter, action, defaultNakedObject, title, flags));
 }
Esempio n. 3
0
        protected ListRepresentation(IOidStrategy oidStrategy, IObjectFacade list, HttpRequestMessage req, RestControlFlags flags, ActionContextFacade actionContext)
            : base(oidStrategy, flags)
        {
            Value = list.ToEnumerable().Select(no => CreateObjectLink(oidStrategy, req, no)).ToArray();

            SetLinks(req, actionContext);
            SetExtensions();
            SetHeader(false);
        }
Esempio n. 4
0
        internal IObjectFacade FilterCollection(IObjectFacade nakedObject, ObjectAndControlData controlData)
        {
            var form = controlData.Form;

            if (form != null && nakedObject != null && nakedObject.Specification.IsCollection)
            {
                nakedObject = Page(nakedObject, nakedObject.Count(), controlData);
                var map      = nakedObject.ToEnumerable().ToDictionary(x => Facade.OidTranslator.GetOidTranslation(x).Encode(), y => y.GetDomainObject <object>());
                var selected = map.Where(kvp => form.Keys.Cast <string>().Contains(kvp.Key) && form[kvp.Key].Contains("true")).Select(kvp => kvp.Value).ToArray();
                return(nakedObject.Select(selected, false));
            }

            return(nakedObject);
        }
        private ActionResult ExecuteAction(ObjectAndControlData controlData, IObjectFacade nakedObject, IActionFacade action)
        {
            if (ActionExecutingAsContributed(action, nakedObject) && action.ParameterCount == 1)
            {
                // contributed action being invoked with a single parm that is the current target
                // no dialog - go straight through

                var ac = new ArgumentsContextFacade {
                    Values = new Dictionary <string, object>(), ValidateOnly = false
                };

                if (nakedObject.Specification.IsCollection && !nakedObject.Specification.IsParseable)
                {
                    var oids = nakedObject.ToEnumerable().Select(no => Facade.OidTranslator.GetOidTranslation(no)).ToArray();
                    var spec = nakedObject.ElementSpecification;

                    var ar = Facade.ExecuteListAction(oids, spec, action.Id, ac);
                    return(AppropriateView(controlData, GetResult(ar), action));
                }
                else
                {
                    var oid = Facade.OidTranslator.GetOidTranslation(nakedObject);
                    var ar  = Facade.ExecuteObjectAction(oid, action.Id, ac);

                    return(AppropriateView(controlData, GetResult(ar), action));
                }
            }

            if (!action.Parameters.Any())
            {
                var ac = new ArgumentsContextFacade {
                    Values = new Dictionary <string, object>(), ValidateOnly = false
                };
                var oid    = Facade.OidTranslator.GetOidTranslation(nakedObject);
                var result = Facade.ExecuteObjectAction(oid, action.Id, ac);

                return(AppropriateView(controlData, GetResult(result), action));
            }

            SetDefaults(nakedObject, action);
            // do after any parameters set by contributed action so this takes priority
            SetSelectedParameters(action);
            SetPagingValues(controlData, nakedObject);
            var property = DisplaySingleProperty(controlData, controlData.DataDict);

            return(View(property == null ? "ActionDialog" : "PropertyEdit", new FindViewModel {
                ContextObject = nakedObject.GetDomainObject(), ContextAction = action, PropertyName = property
            }));
        }
        private static string GetCollectionTitle(IObjectFacade nakedObject, HtmlHelper html)
        {
            int pageSize, maxPage, currentPage, total;
            int count = nakedObject.ToEnumerable().Count();

            if (!html.GetPagingValues(out pageSize, out maxPage, out currentPage, out total))
            {
                total = count;
            }

            string queryInd = nakedObject.Specification.IsQueryable ? MvcUi.QueryResult + ": " : "";
            int    viewSize = count;

            var    typeSpec = nakedObject.ElementSpecification;
            string type     = total == 1 ? typeSpec.SingularName : typeSpec.PluralName;

            return(queryInd + string.Format(MvcUi.ViewingNofXType, viewSize, total, type));
        }
Esempio n. 7
0
 public LinkRepresentation[] GetValue()
 {
     return(collection.ToEnumerable().Select(CreateValueLink).ToArray());
 }
 private static object CreateDefaultLinks(IOidStrategy oidStrategy, HttpRequestMessage req, IActionParameterFacade parameter, IObjectFacade defaultNakedObject, string title, RestControlFlags flags) {
     if (defaultNakedObject.Specification.IsCollection) {
         return defaultNakedObject.ToEnumerable().Select(i => CreateDefaultLink(oidStrategy, req, parameter, i, i.TitleString, flags)).ToArray();
     }
     return CreateDefaultLink(oidStrategy, req, parameter, defaultNakedObject, title, flags);
 }
        private ActionResult ExecuteAction(ObjectAndControlData controlData, IObjectFacade nakedObject, IActionFacade action) {
            if (ActionExecutingAsContributed(action, nakedObject) && action.ParameterCount == 1) {
                // contributed action being invoked with a single parm that is the current target
                // no dialog - go straight through 

                var ac = new ArgumentsContextFacade {Values = new Dictionary<string, object>(), ValidateOnly = false};

                if (nakedObject.Specification.IsCollection && !nakedObject.Specification.IsParseable) {
                    var oids = nakedObject.ToEnumerable().Select(no => Facade.OidTranslator.GetOidTranslation(no)).ToArray();
                    var spec = nakedObject.ElementSpecification;

                    var ar = Facade.ExecuteListAction(oids, spec, action.Id, ac);
                    return AppropriateView(controlData, GetResult(ar), action);
                }
                else {
                    var oid = Facade.OidTranslator.GetOidTranslation(nakedObject);
                    var ar = Facade.ExecuteObjectAction(oid, action.Id, ac);

                    return AppropriateView(controlData, GetResult(ar), action);
                }
            }

            if (!action.Parameters.Any()) {
                var ac = new ArgumentsContextFacade {Values = new Dictionary<string, object>(), ValidateOnly = false};
                var oid = Facade.OidTranslator.GetOidTranslation(nakedObject);
                var result = Facade.ExecuteObjectAction(oid, action.Id, ac);

                return AppropriateView(controlData, GetResult(result), action);
            }

            SetDefaults(nakedObject, action);
            // do after any parameters set by contributed action so this takes priority
            SetSelectedParameters(action);
            SetPagingValues(controlData, nakedObject);
            var property = DisplaySingleProperty(controlData, controlData.DataDict);

            return View(property == null ? "ActionDialog" : "PropertyEdit", new FindViewModel {ContextObject = nakedObject.GetDomainObject(), ContextAction = action, PropertyName = property});
        }
Esempio n. 10
0
        internal ActionResult AppropriateView(ObjectAndControlData controlData, IObjectFacade nakedObject, IActionFacade 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(Facade);

                if (nakedObject.Specification.IsService)
                {
                    object lastObject = Session.LastObject(Facade, ObjectCache.ObjectFlag.BreadCrumb);
                    if (lastObject == null)
                    {
                        return(RedirectHome());
                    }

                    nakedObject = Facade.GetObject(lastObject);
                }

                if (nakedObject.IsCollectionMemento)
                {
                    // if we have returned null and existing object is collection memento need to make
                    // sure action remains action from original collectionMemento.
                    action = nakedObject.MementoAction;
                }
            }

            if (nakedObject.Specification.IsCollection && !nakedObject.Specification.IsParseable)
            {
                int collectionSize = nakedObject.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(IdConstants.PagingData);
                    // is this safe TODO !!
                    return(View("ObjectView", nakedObject.ToEnumerable().First().GetDomainObject()));
                }

                nakedObject = Page(nakedObject, collectionSize, controlData);
                // todo is there a better way to do this ?
                action = action ?? nakedObject.MementoAction;
                int page, pageSize;
                CurrentlyPaging(controlData, collectionSize, out page, out pageSize);
                var format = ViewData["NofCollectionFormat"] as string;
                return(View("StandaloneTable", ActionResultModel.Create(Facade, 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(IdConstants.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.GetDomainObject()) :
                       View(nakedObject.IsNotPersistent ? "PropertyView" : "ViewNameSetAfterTransaction", new PropertyViewModel(nakedObject.GetDomainObject(), propertyName)));
        }
        internal ActionResult AppropriateView(ObjectAndControlData controlData, IObjectFacade nakedObject, IActionFacade 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(Facade);

                if (nakedObject.Specification.IsService) {
                    object lastObject = Session.LastObject(Facade, ObjectCache.ObjectFlag.BreadCrumb);
                    if (lastObject == null) {
                        return RedirectHome();
                    }

                    nakedObject = Facade.GetObject(lastObject);                  
                }

                if (nakedObject.IsCollectionMemento) {
                    // if we have returned null and existing object is collection memento need to make 
                    // sure action remains action from original collectionMemento.
                    action = nakedObject.MementoAction;
                }

            }

            if (nakedObject.Specification.IsCollection && !nakedObject.Specification.IsParseable) {
                int collectionSize = nakedObject.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(IdConstants.PagingData);
                    // is this safe TODO !!
                    return View("ObjectView", nakedObject.ToEnumerable().First().GetDomainObject());
                }

                nakedObject = Page(nakedObject, collectionSize, controlData);
                // todo is there a better way to do this ?
                action = action ?? nakedObject.MementoAction;
                int page, pageSize;
                CurrentlyPaging(controlData, collectionSize, out page, out pageSize);
                var format = ViewData["NofCollectionFormat"] as string;
                return View("StandaloneTable", ActionResultModel.Create(Facade, 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(IdConstants.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.GetDomainObject()) :
                View(nakedObject.IsNotPersistent ? "PropertyView" : "ViewNameSetAfterTransaction", new PropertyViewModel(nakedObject.GetDomainObject(), propertyName));
        }
        internal IObjectFacade FilterCollection(IObjectFacade nakedObject, ObjectAndControlData controlData) {
            var form = controlData.Form;
            if (form != null && nakedObject != null && nakedObject.Specification.IsCollection) {
                nakedObject = Page(nakedObject, nakedObject.Count(), controlData);
                var map = nakedObject.ToEnumerable().ToDictionary(x => Facade.OidTranslator.GetOidTranslation(x).Encode(), y => y.GetDomainObject<object>());
                var selected = map.Where(kvp => form.Keys.Cast<string>().Contains(kvp.Key) && form[kvp.Key].Contains("true")).Select(kvp => kvp.Value).ToArray();
                return nakedObject.Select(selected, false);
            }

            return nakedObject;
        }
        private static string CollectionTable(this HtmlHelper html,
                                              IObjectFacade collectionNakedObject,
                                              Func<IObjectFacade, string> linkFunc,
                                              Func<IAssociationFacade, bool> filter,
                                              Func<IAssociationFacade, int> order,
                                              bool isStandalone,
                                              bool withSelection,
                                              bool withTitle,
                                              bool defaultChecked = false) {
            var table = new TagBuilder("table");
            table.AddCssClass(html.CollectionItemTypeName(collectionNakedObject));
            table.InnerHtml += Environment.NewLine;

            string innerHtml = "";

            var collection = collectionNakedObject.ToEnumerable().ToArray();

            var collectionSpec = collectionNakedObject.ElementSpecification;

            var collectionAssocs = html.CollectionAssociations(collection, collectionSpec, filter, order);

            int index = 0;
            foreach (var item in collection) {
                var row = new TagBuilder("tr");

                if (withSelection) {
                    var cbTag = new TagBuilder("td");
                    int i = index++;
                    string id = "checkbox" + i;
                    string label = GetLabelTag(true, (i + 1).ToString(CultureInfo.InvariantCulture), () => id);
                    cbTag.InnerHtml += (label + html.CheckBox(Encode(html.Facade().OidTranslator.GetOidTranslation(item)), defaultChecked, new { id, @class = IdConstants.CheckboxClass }));
                    row.InnerHtml += cbTag.ToString();
                }

                if (withTitle) {
                    var itemTag = new TagBuilder("td");
                    itemTag.InnerHtml += linkFunc(item);
                    row.InnerHtml += itemTag.ToString();
                }

                string[] collectionValues = collectionAssocs.Select(a => html.GetViewField(new PropertyContext(html.IdHelper(), item, a, false), a.Description, true, true)).ToArray();

                foreach (string s in collectionValues) {
                    row.InnerHtml += new TagBuilder("td") { InnerHtml = s };
                }
                innerHtml += (row + Environment.NewLine);
            }

            var headers = collectionAssocs.Select(a => a.Name).ToArray();
            html.AddHeader(headers, table, isStandalone, withSelection, withTitle, defaultChecked);
            table.InnerHtml += innerHtml;

            return table + html.AddFooter(collectionNakedObject);
        }
        private static bool GetSelectedForChoice(this HtmlHelper html, IObjectFacade choice, IObjectFacade existingNakedObject) {
            IEnumerable<IObjectFacade> existingNakedObjects;

            if (existingNakedObject == null) {
                existingNakedObjects = new IObjectFacade[] { };
            } else if (existingNakedObject.Specification.IsParseable || !existingNakedObject.Specification.IsCollection) {
                // isParseable to catch strings 
                existingNakedObjects = new[] { existingNakedObject };
            } else {
                existingNakedObjects = existingNakedObject.ToEnumerable();
            }

            if (choice.Specification.IsEnum) {
                return existingNakedObjects.Any(no => no != null && choice.EnumIntegralValue == no.EnumIntegralValue);
            }

            if (choice.Specification.IsParseable) {
                return existingNakedObjects.Any(no => choice.TitleString.Trim() == no.TitleString.Trim());
            }
            return existingNakedObjects.Any(choice.Equals);
        }