Exemple #1
0
        private void GetData()
        {
            var rockContext = new RockContext();

            int personId = CurrentPerson != null ? CurrentPerson.Id : 0;

            // Get all of the workflow types
            var allWorkflowTypes = new WorkflowTypeService( rockContext ).Queryable( "ActivityTypes" )
                .OrderBy( w => w.Name )
                .ToList();

            // Get the authorized activities in all workflow types
            var authorizedActivityTypes = AuthorizedActivityTypes( allWorkflowTypes );

            // Get the workflow types that contain authorized activity types
            var workflowTypeIds = allWorkflowTypes
                .Where( w => w.ActivityTypes.Any( a => authorizedActivityTypes.Contains( a.Id ) ) )
                .Select( w => w.Id )
                .Distinct()
                .ToList();

            // Create variable for storing authorized types and the count of active form actions
            var workflowTypeCounts = new Dictionary<int, int>();

            List<Workflow> workflows = null;

            if ( RoleFilter.HasValue && RoleFilter.Value )
            {
                workflows = new WorkflowService( rockContext ).Queryable()
                    .Where( w =>
                        w.ActivatedDateTime.HasValue &&
                        !w.CompletedDateTime.HasValue &&
                        w.InitiatorPersonAlias.PersonId == personId )
                    .ToList();

                workflowTypeIds.ForEach( id =>
                    workflowTypeCounts.Add( id, workflows.Where( w => w.WorkflowTypeId == id ).Count() ) );
            }
            else
            {
                // Get all the active forms for any of the authorized activities
                var activeForms = new WorkflowActionService( rockContext ).Queryable( "ActionType.ActivityType.WorkflowType, Activity.Workflow" )
                    .Where( a =>
                        a.ActionType.WorkflowFormId.HasValue &&
                        !a.CompletedDateTime.HasValue &&
                        a.Activity.ActivatedDateTime.HasValue &&
                        !a.Activity.CompletedDateTime.HasValue &&
                        a.Activity.Workflow.ActivatedDateTime.HasValue &&
                        !a.Activity.Workflow.CompletedDateTime.HasValue &&
                        authorizedActivityTypes.Contains( a.ActionType.ActivityTypeId ) &&
                        (
                            ( a.Activity.AssignedPersonAlias != null && a.Activity.AssignedPersonAlias.PersonId == personId ) ||
                            ( a.Activity.AssignedGroup != null && a.Activity.AssignedGroup.Members.Any( m => m.PersonId == personId ) )
                        )
                    )
                    .ToList();

                // Get any workflow types that have authorized activites and get the form count
                workflowTypeIds.ForEach( w =>
                    workflowTypeCounts.Add( w, activeForms.Where( a => a.Activity.Workflow.WorkflowTypeId == w ).Count() ) );

                workflows = activeForms
                    .Select( a => a.Activity.Workflow )
                    .Distinct()
                    .ToList();
            }

            var displayedTypes = new List<WorkflowType>();
            foreach ( var workflowType in allWorkflowTypes.Where( w => workflowTypeCounts.Keys.Contains( w.Id ) ) )
            {
                if ( workflowTypeCounts[workflowType.Id] > 0 )
                {
                    // Always show any types that have active assignments assigned to user
                    displayedTypes.Add( workflowType );
                }
                else
                {
                    // If there are not any active assigned activities, and not filtering by active, then also
                    // show any types that user is authorized to edit
                    if ( ( !StatusFilter.HasValue || !StatusFilter.Value ) &&
                        workflowType.IsAuthorized( Authorization.EDIT, CurrentPerson ) )
                    {
                        displayedTypes.Add( workflowType );
                    }
                }
            }

            // Create a query to return workflow type, the count of active action forms, and the selected class
            var qry = displayedTypes
                .Select( w => new
                {
                    WorkflowType = w,
                    Count = workflowTypeCounts[w.Id],
                    Class = ( SelectedWorkflowTypeId.HasValue && SelectedWorkflowTypeId.Value == w.Id ) ? "active" : ""
                } );

            rptWorkflowTypes.DataSource = qry.ToList();
            rptWorkflowTypes.DataBind();

            WorkflowType selectedWorkflowType = null;
            if ( SelectedWorkflowTypeId.HasValue )
            {
                selectedWorkflowType = allWorkflowTypes
                    .Where( w => w.Id == SelectedWorkflowTypeId.Value )
                    .FirstOrDefault();

                AddAttributeColumns( selectedWorkflowType );
            }

            if ( selectedWorkflowType != null && workflowTypeCounts.Keys.Contains( selectedWorkflowType.Id ) )
            {
                var workflowQry = workflows.Where( w => w.WorkflowTypeId == selectedWorkflowType.Id ).AsQueryable();

                var sortProperty = gWorkflows.SortProperty;
                if ( sortProperty != null )
                {
                    gWorkflows.DataSource = workflowQry.Sort( sortProperty ).ToList();
                }
                else
                {
                    gWorkflows.DataSource = workflowQry.OrderByDescending( s => s.CreatedDateTime ).ToList();
                }

                gWorkflows.DataBind();
                gWorkflows.Visible = true;

                lWorkflow.Text = workflows.Where( w => w.WorkflowTypeId == selectedWorkflowType.Id ).Select( w => w.WorkflowType.Name ).FirstOrDefault() + " Workflows";
            }
            else
            {
                gWorkflows.Visible = false;
            }
        }
        private List<WorkflowAction> GetWorkflows()
        {
            var actions = new List<WorkflowAction>();

            if ( CurrentPerson != null )
            {
                using ( var rockContext = new RockContext() )
                {
                    var categoryIds = GetCategories( rockContext );

                    var qry = new WorkflowService( rockContext ).Queryable()
                        .Where( w =>
                            w.ActivatedDateTime.HasValue &&
                            !w.CompletedDateTime.HasValue &&
                            w.InitiatorPersonAlias.PersonId == CurrentPerson.Id );

                    if ( categoryIds.Any() )
                    {
                        qry = qry
                            .Where( w =>
                                w.WorkflowType.CategoryId.HasValue &&
                                categoryIds.Contains( w.WorkflowType.CategoryId.Value ) );
                    }

                    foreach ( var workflow in qry.OrderBy( w => w.ActivatedDateTime ) )
                    {
                        var activity = new WorkflowActivity();
                        activity.Workflow = workflow;

                        var action = new WorkflowAction();
                        action.Activity = activity;

                        actions.Add( action );
                    }
                }
            }

            return actions;
        }
Exemple #3
0
        private void GetData()
        {
            var rockContext = new RockContext();

            int personId = CurrentPerson != null ? CurrentPerson.Id : 0;

            // Get all of the workflow types
            var allWorkflowTypes = new WorkflowTypeService( rockContext ).Queryable( "ActivityTypes" )
                .OrderBy( w => w.Name )
                .ToList();

            // Get the authorized activities in all workflow types
            var authorizedActivityTypes = AuthorizedActivityTypes( allWorkflowTypes );

            // Get the workflow types that contain authorized activity types
            var workflowTypeIds = allWorkflowTypes
                .Where( w => w.ActivityTypes.Any( a => authorizedActivityTypes.Contains( a.Id ) ) )
                .Select( w => w.Id )
                .Distinct()
                .ToList();

            // Create variable for storing authorized types and the count of active form actions
            var workflowTypeCounts = new Dictionary<int, int>();

            List<Workflow> workflows = null;

            if ( RoleFilter.HasValue && RoleFilter.Value )
            {
                workflows = new WorkflowService( rockContext ).Queryable()
                    .Where( w =>
                        w.ActivatedDateTime.HasValue &&
                        !w.CompletedDateTime.HasValue &&
                        w.InitiatorPersonAlias.PersonId == personId )
                    .ToList();

                workflowTypeIds.ForEach( id =>
                    workflowTypeCounts.Add( id, workflows.Where( w => w.WorkflowTypeId == id ).Count() ) );
            }
            else
            {

                // Get all the active forms for any of the authorized activities
                var activeForms = new WorkflowActionService( rockContext ).Queryable( "ActionType.ActivityType.WorkflowType, Activity.Workflow" )
                    .Where( a =>
                        a.ActionType.WorkflowFormId.HasValue &&
                        !a.CompletedDateTime.HasValue &&
                        a.Activity.ActivatedDateTime.HasValue &&
                        !a.Activity.CompletedDateTime.HasValue &&
                        a.Activity.Workflow.ActivatedDateTime.HasValue &&
                        !a.Activity.Workflow.CompletedDateTime.HasValue &&
                        authorizedActivityTypes.Contains( a.ActionType.ActivityTypeId ) &&
                        (
                            ( a.Activity.AssignedPersonAlias != null && a.Activity.AssignedPersonAlias.PersonId == personId ) ||
                            ( a.Activity.AssignedGroup != null && a.Activity.AssignedGroup.Members.Any( m => m.PersonId == personId ) )
                        )
                    )
                    .ToList();

                // Get any workflow types that have authorized activites and get the form count
                workflowTypeIds.ForEach( w =>
                    workflowTypeCounts.Add( w, activeForms.Where( a => a.Activity.Workflow.WorkflowTypeId == w ).Count() ) );

                workflows = activeForms
                    .Select( a => a.Activity.Workflow )
                    .Distinct()
                    .ToList();
            }

            // Create a query to return workflow type, the count of active action forms, and the selected class
            var qry = allWorkflowTypes
                .Where( w => workflowTypeCounts.Keys.Contains( w.Id ) )
                .Select( w => new
                {
                    WorkflowType = w,
                    Count = workflowTypeCounts[w.Id],
                    Class = ( SelectedWorkflowTypeId.HasValue && SelectedWorkflowTypeId.Value == w.Id ) ? "active" : ""
                } );

            // If displaying active only, update query to exclude those workflow types without any active form actions
            if ( StatusFilter.HasValue && StatusFilter.Value )
            {
                qry = qry.Where( q => q.Count > 0 );
            }

            rptWorkflowTypes.DataSource = qry.ToList();
            rptWorkflowTypes.DataBind();

            WorkflowType selectedWorkflowType = null;
            if ( SelectedWorkflowTypeId.HasValue )
            {
                selectedWorkflowType = allWorkflowTypes
                    .Where( w =>
                        w.Id == SelectedWorkflowTypeId.Value &&
                        workflowTypeCounts.Keys.Contains( SelectedWorkflowTypeId.Value ) )
                    .FirstOrDefault();
            }

            if ( selectedWorkflowType != null )
            {
                AddAttributeColumns( selectedWorkflowType );

                gWorkflows.DataSource = workflows.Where( w => w.WorkflowTypeId == selectedWorkflowType.Id ).ToList();
                gWorkflows.DataBind();
                gWorkflows.Visible = true;

            }
            else
            {
                gWorkflows.Visible = false;
            }
        }