Exemplo n.º 1
0
        public static DocumentationActionDraft MapToDocumentationActionDraft(this GenericActionViewModel model, PublishModeEnum publishMode, Dictionary <int, string> wbsActions)
        {
            var action = new DocumentationActionDraft
            {
                Label           = model.Label,
                Duration        = model.Duration,
                SkillId         = model.SkillId,
                IsKeyTask       = model.IsKeyTask,
                ThumbnailHash   = model.ImageHash,
                CustomTextValue = model.CustomTextValues != null?model.CustomTextValues.GetOrDefault(ProcessReferentialIdentifier.CustomTextLabel) : string.Empty,
                                      CustomTextValue2 = model.CustomTextValues != null?model.CustomTextValues.GetOrDefault(ProcessReferentialIdentifier.CustomTextLabel2) : string.Empty,
                                                             CustomTextValue3 = model.CustomTextValues != null?model.CustomTextValues.GetOrDefault(ProcessReferentialIdentifier.CustomTextLabel3) : string.Empty,
                                                                                    CustomTextValue4 = model.CustomTextValues != null?model.CustomTextValues.GetOrDefault(ProcessReferentialIdentifier.CustomTextLabel4) : string.Empty,
                                                                                                           CustomNumericValue = model.CustomNumericValues != null?model.CustomNumericValues.GetOrDefault(ProcessReferentialIdentifier.CustomNumericLabel) : null,
                                                                                                                                    CustomNumericValue2 = model.CustomNumericValues != null?model.CustomNumericValues.GetOrDefault(ProcessReferentialIdentifier.CustomNumericLabel2) : null,
                                                                                                                                                              CustomNumericValue3 = model.CustomNumericValues != null?model.CustomNumericValues.GetOrDefault(ProcessReferentialIdentifier.CustomNumericLabel3) : null,
                                                                                                                                                                                        CustomNumericValue4 = model.CustomNumericValues != null?model.CustomNumericValues.GetOrDefault(ProcessReferentialIdentifier.CustomNumericLabel4) : null
            };

            if (model.ReferentialFieldValues == null)
            {
                return(action);
            }

            // Build reference
            foreach (var reference in model.ReferentialFieldValues)
            {
                foreach (var referenceValue in reference.Values)
                {
                    action.ReferentialDocumentations.Add(new ReferentialDocumentationActionDraft
                    {
                        Quantity      = referenceValue.Quantity,
                        ReferentialId = referenceValue.ReferentialId,
                        RefNumber     = (int)reference.ReferentialFieldId - 3
                    });
                }
            }
            return(action);
        }
Exemplo n.º 2
0
        public static List <ActionValueViewModel> BuildMultiValueRefs(GenericActionViewModel action, ProcessReferentialIdentifier refId)
        {
            var model      = new List <ActionValueViewModel>();
            var actionRefs = action.ReferentialFieldValues.FirstOrDefault(r => r.ReferentialFieldId == refId);
            var refField   = action.ReferentialsFields.FirstOrDefault(r => r.ReferentialFieldId == refId);

            if (actionRefs != null && actionRefs.Values.Count != 0 && refField != null)
            {
                var refFieldElements = refField.ReferentialsFieldElements;
                var refValues        = actionRefs.Values;

                foreach (var refValue in refValues)
                {
                    var refe = refFieldElements.FirstOrDefault(r => r.Id == refValue.ReferentialId);
                    if (refe != null)
                    {
                        var fileModel = BuildFile(null, refe.Label, refValue.Quantity);
                        model.Add(fileModel);
                    }
                }
            }
            return(model);
        }
Exemplo n.º 3
0
        public static ActionColumnViewModel GetActionValues(string header,
                                                            GenericActionViewModel action,
                                                            Dictionary <int, string> wbsValues = null)
        {
            var model = new ActionColumnViewModel {
                Values = new List <ActionValueViewModel>()
            };

            switch (header)
            {
            case nameof(PublishedAction.WBS):
                model.Values.Add(new ActionValueViewModel
                {
                    Type  = "Text",
                    Value = wbsValues?.GetOrDefault(action.ActionId) ?? action.WBS
                });
                break;

            case nameof(PublishedAction.Label):
                model.Values.Add(new ActionValueViewModel
                {
                    Type  = "Text",
                    Value = action.Label ?? string.Empty
                });
                break;

            case nameof(PublishedAction.Thumbnail):
                model.Values.Add(new ActionValueViewModel
                {
                    Type     = "Image",
                    Value    = action.ImageHash,
                    FileHash = action.ImageHash,
                    FileExt  = action.Extension
                });
                break;

            case nameof(PublishedAction.Duration):
                model.Values.Add(new ActionValueViewModel
                {
                    Type  = "Text",
                    Value = TicksUtil.TicksToString(action.Duration, action.TimeScale)
                });
                break;

            case nameof(PublishedAction.Refs1):
                model.Values = BuildMultiValueRefs(action, ProcessReferentialIdentifier.Ref1);
                break;

            case nameof(PublishedAction.Refs2):
                model.Values = BuildMultiValueRefs(action, ProcessReferentialIdentifier.Ref2);
                break;

            case nameof(PublishedAction.Refs3):
                model.Values = BuildMultiValueRefs(action, ProcessReferentialIdentifier.Ref3);
                break;

            case nameof(PublishedAction.Refs4):
                model.Values = BuildMultiValueRefs(action, ProcessReferentialIdentifier.Ref4);
                break;

            case nameof(PublishedAction.Refs5):
                model.Values = BuildMultiValueRefs(action, ProcessReferentialIdentifier.Ref5);
                break;

            case nameof(PublishedAction.Refs6):
                model.Values = BuildMultiValueRefs(action, ProcessReferentialIdentifier.Ref6);
                break;

            case nameof(PublishedAction.Refs7):
                model.Values = BuildMultiValueRefs(action, ProcessReferentialIdentifier.Ref7);
                break;

            case nameof(PublishedAction.CustomTextValue):
                model.Values.Add(new ActionValueViewModel
                {
                    Type  = "Text",
                    Value = action.CustomTextValues != null ? action.CustomTextValues
                            .Where(t => t.Key == ProcessReferentialIdentifier.CustomTextLabel)
                            .Select(t => t.Value)
                            .DefaultIfEmpty(string.Empty)
                            .FirstOrDefault() : string.Empty
                });
                break;

            case nameof(PublishedAction.CustomTextValue2):
                model.Values.Add(new ActionValueViewModel
                {
                    Type  = "Text",
                    Value = action.CustomTextValues != null ? action.CustomTextValues
                            .Where(t => t.Key == ProcessReferentialIdentifier.CustomTextLabel2)
                            .Select(t => t.Value)
                            .DefaultIfEmpty(string.Empty)
                            .FirstOrDefault() : string.Empty
                });
                break;

            case nameof(PublishedAction.CustomTextValue3):
                model.Values.Add(new ActionValueViewModel
                {
                    Type  = "Text",
                    Value = action.CustomTextValues != null ? action.CustomTextValues
                            .Where(t => t.Key == ProcessReferentialIdentifier.CustomTextLabel3)
                            .Select(t => t.Value)
                            .DefaultIfEmpty(string.Empty)
                            .FirstOrDefault() : string.Empty
                });
                break;

            case nameof(PublishedAction.CustomTextValue4):
                model.Values.Add(new ActionValueViewModel
                {
                    Type  = "Text",
                    Value = action.CustomTextValues != null ? action.CustomTextValues
                            .Where(t => t.Key == ProcessReferentialIdentifier.CustomTextLabel4)
                            .Select(t => t.Value)
                            .DefaultIfEmpty(string.Empty)
                            .FirstOrDefault() : string.Empty
                });
                break;

            case nameof(PublishedAction.CustomNumericValue):
                model.Values.Add(new ActionValueViewModel
                {
                    Type  = "Text",
                    Value = action.CustomNumericFields != null ? action.CustomNumericValues
                            .Where(t => t.Key == ProcessReferentialIdentifier.CustomNumericLabel)
                            .Select(t => $"{t.Value}")
                            .DefaultIfEmpty(string.Empty)
                            .FirstOrDefault() : string.Empty
                });
                break;

            case nameof(PublishedAction.CustomNumericValue2):
                model.Values.Add(new ActionValueViewModel
                {
                    Type  = "Text",
                    Value = action.CustomNumericFields != null ? action.CustomNumericValues
                            .Where(t => t.Key == ProcessReferentialIdentifier.CustomNumericLabel2)
                            .Select(t => $"{t.Value}")
                            .DefaultIfEmpty(string.Empty)
                            .FirstOrDefault() : string.Empty
                });
                break;

            case nameof(PublishedAction.CustomNumericValue3):
                model.Values.Add(new ActionValueViewModel
                {
                    Type  = "Text",
                    Value = action.CustomNumericFields != null ? action.CustomNumericValues
                            .Where(t => t.Key == ProcessReferentialIdentifier.CustomNumericLabel3)
                            .Select(t => $"{t.Value}")
                            .DefaultIfEmpty(string.Empty)
                            .FirstOrDefault() : string.Empty
                });
                break;

            case nameof(PublishedAction.CustomNumericValue4):
                model.Values.Add(new ActionValueViewModel
                {
                    Type  = "Text",
                    Value = action.CustomNumericFields != null ? action.CustomNumericValues
                            .Where(t => t.Key == ProcessReferentialIdentifier.CustomNumericLabel4)
                            .Select(t => $"{t.Value}")
                            .DefaultIfEmpty(string.Empty)
                            .FirstOrDefault() : string.Empty
                });
                break;

            default:
                var attribute = ReflectionHelper.GetPropertyValue(action, header);
                model.Values.Add(new ActionValueViewModel
                {
                    Type  = "Text",
                    Value = attribute != null ? attribute.ToString() : string.Empty
                });
                break;
            }
            return(model);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Show more information about an action
        /// Routing create to be able to access as: /Action/Id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <ActionResult> Details(int?PublishModeFilter, int?id, bool computeReadNext = false, bool partial = false)
        {
            if (!id.HasValue)
            {
                return(HttpNotFound());
            }

            var action = await _prepareService.GetPublishedAction(id.Value);

            if (action == null)
            {
                return(HttpNotFound());
            }

            var publication = await _prepareService.GetLightPublication(action.Publication.PublicationId);

            ViewBag.ComputeReadNext   = computeReadNext;
            ViewBag.publishModeFilter = PublishModeFilter.Value;

            // TODO : Faire le calcul du chemin critique en incluant les tâches des sous-process
            // Change to normal WBS order (alphanumeric)
            //if (computeReadNext)
            //{
            //    var tempCriticalPath = publication.PublishedActions.CriticalPath(p => p.Successors, p => p.BuildFinish - p.BuildStart);
            //    var criticalPath = new List<PublishedAction>();
            //    for (int i = tempCriticalPath.Count(); i > 0; i--)
            //        criticalPath.Add(tempCriticalPath.ElementAt(i - 1));

            //    var nextActionIndex = criticalPath.IndexOf(criticalPath.First(u => u.PublishedActionId == id)) + 1;
            //    ViewBag.NextAction = nextActionIndex >= criticalPath.Count ? 0 : criticalPath[nextActionIndex].PublishedActionId;

            //}


            var actionIndex = action.Publication.PublishedActions.OrderBy(a => a, new WBSComparer()).Select(p => p.PublishedActionId).ToList().IndexOf(action.PublishedActionId);
            var previousId  = actionIndex - 1 >= 0 ? action.Publication.PublishedActions.OrderBy(a => a, new WBSComparer()).Select(p => p.PublishedActionId).ToList().ElementAtOrDefault(actionIndex - 1) : 0;
            var nextId      = action.Publication.PublishedActions.OrderBy(a => a, new WBSComparer()).Select(p => p.PublishedActionId).ToList().ElementAtOrDefault(actionIndex + 1);

            var localizations             = action.Publication.Localizations.ToDictionary(k => k.ResourceKey, v => v.Value);
            var documentationReferentials = await _referentialsService.GetDocumentationReferentials(action.Publication.ProcessId);

            localizations = ActionMapper.UpdateLocalizationLabelForDetail(localizations, documentationReferentials);
            var visibleColumns = ActionMapper.GetDetailDispositions(action.Publication, (PublishModeEnum)PublishModeFilter.Value);
            var values         = new Dictionary <string, ActionColumnViewModel>();
            var actionHeaders  = ActionMapper.GetDetailColumnHeader(visibleColumns, localizations);

            if (computeReadNext)
            {
                ViewBag.NextAction = nextId;
            }

            foreach (var setting in visibleColumns)
            {
                (List <RefsCollection> refs, List <CustomLabel> customLabel) = ActionMapper.BuildReferenceAndCustomLabel(action, localizations);
                var attribute = ReflectionHelper.GetPropertyValue(action, setting);
                values.Add(setting, ActionMapper.GetPublishedActionAttributes(action, attribute, setting, setting, localizations, refs, customLabel));
            }

            //Populate Action detail dispositions
            var detailsDisposition = new List <string>();

            if ((PublishModeEnum)PublishModeFilter.Value == PublishModeEnum.Formation)
            {
                if (publication.Formation_ActionDisposition.IsNotNullNorEmpty())
                {
                    detailsDisposition = publication.Formation_ActionDisposition.Split(',').ToList();
                }
            }
            else if ((PublishModeEnum)PublishModeFilter.Value == PublishModeEnum.Inspection)
            {
                if (publication.Inspection_ActionDisposition.IsNotNullNorEmpty())
                {
                    detailsDisposition = publication.Inspection_ActionDisposition.Split(',').ToList();
                }
            }



            var model = new GenericActionViewModel
            {
                ActionHeaders  = actionHeaders,
                ActionId       = action.PublishedActionId,
                Label          = action.Label,
                ColumnValues   = values,
                VideoExtension = action.CutVideo != null?MimeMapping.GetMimeMapping(action.CutVideo.Extension) : null,
                                     VideoHash                 = action.CutVideo?.Hash,
                                     VideoExt                  = action.CutVideo?.Extension,
                                     ProcessId                 = action.Publication.ProcessId,
                                     ProcessLabel              = action.Publication.Process.Label,
                                     PublicationVersion        = action.Publication.Version,
                                     PublicationVersionIsMajor = action.Publication.IsMajor,
                                     PreviousActionId          = previousId,
                                     NextActionId              = nextId,
                                     IsKeyTask                 = action.IsKeyTask,
                                     PublishModeFilter         = PublishModeFilter.Value,
                                     DetailActionDispositions  = detailsDisposition
            };

            if (partial)
            {
                return(PartialView(model));
            }

            return(View(model));
        }