Example #1
0
        private static DetailsCommandResult CreateDetailsResult(IEditableRoot editableRoot)
        {
            var result = new DetailsCommandResult { Id = editableRoot.Id, DisplayName = editableRoot.ProcessDisplayName, IsTabbedUI = IsTabbedUI(editableRoot) };
            var visibleFields = new HashSet<string>(editableRoot.Sections.SelectMany(s => s.Fields).Where(f => !f.IsHidden).Select(f => f.SystemName));
            var validationContext = editableRoot.GetValidationContext();

            foreach (var sect in editableRoot.Sections)
            {
                var section = new SectionInfo { Name = sect.Name };
                var row = new RowInfo();
                var rowLength = 0d;

                foreach (var field in sect.Fields)
                {
                    var prop = editableRoot.GetPropertyByName(field.SystemName);
                    if (!visibleFields.Contains(prop.Name))
                    {
                        continue;
                    }

                    var fieldInfo = FieldInfoFactory.Create(prop, editableRoot, field, GetValue(prop, editableRoot), validationContext);
                    if (rowLength + fieldInfo.Width > 100)
                    {
                        if (row.Fields.Any())
                            section.Rows.Add(row);
                        row = new RowInfo();
                        rowLength = fieldInfo.Width >= 100 ? 100 : fieldInfo.Width;
                    }
                    else
                        rowLength += fieldInfo.Width;

                    row.Fields.Add(fieldInfo);
                }

                if (row.Fields.Any())
                    section.Rows.Add(row);

                if (section.Rows.Any())
                    result.Sections.Add(section);
            }


            result.States = new List<IStateInfo>();
            var supportStates = editableRoot as ISupportStates;
            if (supportStates != null)
            {
                foreach (var s in supportStates.StateManager.States)
                {
                    result.States.Add(new StateInfo(s.Name, s.Guid));
                }
            }

            result.CurrentStateGuid = editableRoot.GetCurrentStateGuid();

            return result;
        }