protected override DriverResult Editor(DynamicButtonToWorkflowsSettingsPart part, dynamic shapeHelper) { return(ContentShape("Parts_DynamicButtonToWorkflowsSettings_Edit", () => { IEnumerable <DynamicButtonToWorkflowsEdit> buttons = null; var buttonsWithErrors = _controllerContextAccessor.Context.Controller.TempData[Prefix + "ButtonsWithErrors"]; if (buttonsWithErrors == null) { buttons = _dynamicButtonToWorkflowsService.GetButtons().Select(s => new DynamicButtonToWorkflowsEdit { Id = s.Id, ButtonName = s.ButtonName, ButtonText = s.ButtonText, ButtonDescription = s.ButtonDescription, ButtonMessage = s.ButtonMessage, ButtonAsync = s.ButtonAsync, GlobalIdentifier = s.GlobalIdentifier, Delete = false }); } else { buttons = ((IEnumerable <DynamicButtonToWorkflowsEdit>)buttonsWithErrors).Where(x => x.Delete == false); } var model = new DynamicButtonToWorkflowsSettingsVM { Buttons = buttons }; return shapeHelper.EditorTemplate( TemplateName: TemplateName, Model: model, Prefix: Prefix); }).OnGroup("Buttons")); }
public override bool CanExecute(WorkflowContext workflowContext, ActivityContext activityContext) { try { // Recupero il bottone associato all'evento var buttonSelected = activityContext.GetState <string>("DynamicButton"); // Verifico che all'evento sia effettivamente associato un bottone e di avere le informazioni sul bottone cliccato nel workflowContext if (!string.IsNullOrWhiteSpace(buttonSelected) && workflowContext.Tokens.ContainsKey("ButtonName")) { // Recupero il bottone che è stato cliccato. Se esiste, ne ottengo il Guid e lo confronto con quello del bottone selezionato. var clickedButtonName = workflowContext.Tokens["ButtonName"].ToString(); if (!string.IsNullOrWhiteSpace(clickedButtonName)) { var clickedButtonIdentifier = _dynamicButtonToWorkflowsService.GetButtons().Where(w => w.ButtonName == clickedButtonName).Select(s => s.GlobalIdentifier).FirstOrDefault(); return(clickedButtonIdentifier.ToString() == buttonSelected); } } return(false); } catch { return(false); } }
public int UpdateFrom6() { SchemaBuilder.AlterTable("DynamicButtonToWorkflowsRecord", table => table .AddColumn <string>("GlobalIdentifier") ); var buttonsWithoutGuid = _dynamicButtonToWorkflowsService.GetButtons().Where(w => String.IsNullOrWhiteSpace(w.GlobalIdentifier)); if (buttonsWithoutGuid.Count() > 0) { List <DynamicButtonToWorkflowsEdit> buttonList = new List <DynamicButtonToWorkflowsEdit>(); var activities = _activityRepository.Table.Where(w => w.Name.Equals("DynamicButtonEvent")); var typesWithButtons = _contentDefinitionManager.ListTypeDefinitions().Where(w => w.Parts.Any(p => p.PartDefinition.Name == "DynamicButtonToWorkflowsPart")).ToList(); foreach (var button in buttonsWithoutGuid) { // Associo un Guid a tutti i bottoni già esistenti che non ne hanno uno DynamicButtonToWorkflowsEdit buttonData = new DynamicButtonToWorkflowsEdit(); buttonData.Id = button.Id; buttonData.ButtonText = button.ButtonText; buttonData.ButtonAsync = button.ButtonAsync; buttonData.ButtonDescription = button.ButtonDescription; buttonData.ButtonMessage = button.ButtonMessage; buttonData.ButtonName = button.ButtonName; buttonData.GlobalIdentifier = Guid.NewGuid().ToString(); buttonData.Delete = false; buttonList.Add(buttonData); // Correggo i riferimenti ai bottoni nelle parti string partSettingToEdit = string.Format("{{{0}}}", button.Id); foreach (var type in typesWithButtons) { var part = type.Parts.Where(w => w.PartDefinition.Name == "DynamicButtonToWorkflowsPart").FirstOrDefault(); if (part != null) { part.Settings["DynamicButtonsSetting.Buttons"] = part.Settings["DynamicButtonsSetting.Buttons"].Replace(partSettingToEdit, string.Format("{{{0}}}", buttonData.GlobalIdentifier)); _contentDefinitionManager.StoreTypeDefinition(type); } } // Correggo i riferimenti ai bottoni nelle activities dei workflows string activitySettingToEdit = string.Format("\"DynamicButton\":\"{0}\"", button.Id); var activitiesWithButton = activities.Where(w => w.State.Contains(activitySettingToEdit)); foreach (var activity in activitiesWithButton) { activity.State = activity.State.Replace(activitySettingToEdit, string.Format("\"DynamicButton\":\"{0}\"", buttonData.GlobalIdentifier)); _activityRepository.Update(activity); } } _dynamicButtonToWorkflowsService.UpdateButtons(buttonList); _activityRepository.Flush(); } return(7); }
protected override DriverResult Editor(DynamicButtonToWorkflowsPart part, dynamic shapeHelper) { var settings = part.TypePartDefinition.Settings.GetModel <DynamicButtonsSetting>(); var buttonList = _dynamicButtonToWorkflowsService.GetButtons().Where(w => settings.List.ToList().Contains("{" + w.GlobalIdentifier + "}")); return(ContentShape("Parts_DynamicButtonToWorkflows", () => shapeHelper.EditorTemplate(TemplateName: "Parts/DynamicButtonToWorkflows", Model: buttonList.ToList(), Prefix: Prefix))); }
public IEnumerable <Permission> GetPermissions() { List <Permission> permissions = new List <Permission>(); IList <DynamicButtonToWorkflowsRecord> dynamicButtons = _dynamicButtonToWorkflowsService.GetButtons(); foreach (var button in dynamicButtons) { permissions.Add(_dynamicButtonToWorkflowsService.GetButtonPermission(button.ButtonName)); } return(permissions); }
public void Describe(DescribeContext context) { Func <IShapeFactory, dynamic> form = shape => { var frm = _shapeFactory.Form( Id: "_DynamicButtonSelect", _Buttons: _shapeFactory.SelectList( Id: "DynamicButton", Name: "DynamicButton", Title: T("Dynamic Button"), Description: T("Select a dynamic button."), Size: 10, Multiple: false ) ); foreach (var contentType in _dynamicButtonToWorkflowsService.GetButtons().OrderBy(o => o.ButtonName)) { var optionText = contentType.ButtonName; if (!string.IsNullOrWhiteSpace(contentType.ButtonDescription)) { optionText = optionText + " (" + contentType.ButtonDescription + ")"; } frm._Buttons.Add(new SelectListItem { Value = contentType.GlobalIdentifier, Text = optionText }); } return(frm); //var f = _shapeFactory.Form( // Id: "_AnyOfContentTypes", // _Parts: _shapeFactory.SelectList( // Id: "contenttypes", Name: "ContentTypes", // Title: T("Content types"), // Description: T("Select some content types."), // Size: 10, // Multiple: true // ) // ); //f._Parts.Add(new SelectListItem { Value = "", Text = T("Any").Text }); //foreach (var contentType in _contentDefinitionManager.ListTypeDefinitions().OrderBy(x => x.DisplayName)) { // f._Parts.Add(new SelectListItem { Value = contentType.Name, Text = contentType.DisplayName }); //} //return f; }; context.Form("_DynamicButtonSelectForm", form); }