Example #1
0
        public DetailViewData(Person currentPerson, Models.GrantAllocation grantAllocation
                              , GrantAllocationBasicsViewData grantAllocationBasicsViewData
                              , EntityNotesViewData grantAllocationNotesViewData
                              , EntityNotesViewData grantAllocationNoteInternalsViewData
                              , ViewGoogleChartViewData viewGoogleChartViewData
                              , GridSpec <Models.ProjectGrantAllocationRequest> projectGrantAllocationRequestsGridSpec
                              , GrantAllocationExpendituresGridSpec grantAllocationExpendituresGridSpec)
            : base(currentPerson, grantAllocation)
        {
            PageTitle       = grantAllocation.GrantAllocationName.ToEllipsifiedStringClean(110);
            BreadCrumbTitle = $"{Models.FieldDefinition.GrantAllocation.GetFieldDefinitionLabel()} Detail";

            GrantAllocationBasicsViewData = grantAllocationBasicsViewData;
            GrantAllocationNotesViewData  = grantAllocationNotesViewData;

            NewGrantAllocationNoteUrl            = grantAllocation.GetNewNoteUrl();
            GrantAllocationNoteInternalsViewData = grantAllocationNoteInternalsViewData;

            ViewGoogleChartViewData = viewGoogleChartViewData;

            var projectGrantAllocationExpenditures = GrantAllocation.ProjectGrantAllocationExpenditures.ToList();

            CalendarYearsForProjectExpenditures = projectGrantAllocationExpenditures.CalculateCalendarYearRangeForExpenditures(grantAllocation);

            ProjectCalendarYearExpendituresGridSpec = new ProjectCalendarYearExpendituresGridSpec(CalendarYearsForProjectExpenditures)
            {
                ObjectNameSingular  = $"{Models.FieldDefinition.Project.GetFieldDefinitionLabel()}",
                ObjectNamePlural    = $"{Models.FieldDefinition.Project.GetFieldDefinitionLabelPluralized()}",
                SaveFiltersInCookie = true
            };

            ProjectCalendarYearExpendituresGridName    = "projectsCalendarYearExpendituresFromGrantAllocationGrid";
            ProjectCalendarYearExpendituresGridDataUrl = SitkaRoute <GrantAllocationController> .BuildUrlFromExpression(tc => tc.ProjectCalendarYearExpendituresGridJsonData(grantAllocation));

            ProjectGrantAllocationRequestsGridSpec    = projectGrantAllocationRequestsGridSpec;
            ProjectGrantAllocationRequestsGridName    = "projectsGrantAllocationRequestsFromGrantAllocationGrid";
            ProjectGrantAllocationRequestsGridDataUrl = SitkaRoute <GrantAllocationController> .BuildUrlFromExpression(tc => tc.ProjectGrantAllocationRequestsGridJsonData(grantAllocation));

            GrantAllocationExpendituresGridSpec    = grantAllocationExpendituresGridSpec;
            GrantAllocationExpendituresGridName    = "grantAllocationExpendituresGrid";
            GrantAllocationExpendituresGridDataUrl = SitkaRoute <GrantAllocationController> .BuildUrlFromExpression(gac => gac.GrantAllocationExpendituresGridJsonData(grantAllocation));

            GrantAllocationBudgetLineItemsViewData = new GrantAllocationBudgetLineItemsViewData(currentPerson, grantAllocation, grantAllocation.GrantAllocationBudgetLineItems.ToList());
            GrantAllocationBudgetVsActualsViewData = new GrantAllocationBudgetVsActualsViewData(currentPerson, grantAllocation);

            var canEditDocuments = new GrantAllocationEditAsAdminFeature().HasPermission(currentPerson, grantAllocation).HasPermission;

            GrantAllocationDetailsFileDetailsViewData = new FileDetailsViewData(
                EntityDocument.CreateFromEntityDocument(new List <IEntityDocument>(grantAllocation.GrantAllocationFileResources)),
                SitkaRoute <GrantAllocationController> .BuildUrlFromExpression(x => x.NewGrantAllocationFiles(grantAllocation.PrimaryKey)),
                canEditDocuments,
                Models.FieldDefinition.GrantAllocation
                );
        }
Example #2
0
        public ViewResult GrantAllocationDetail(GrantAllocationPrimaryKey grantAllocationPrimaryKey)
        {
            var grantAllocation = grantAllocationPrimaryKey.EntityObject;

            if (grantAllocation == null)
            {
                throw new Exception($"Could not find GrantAllocationID # {grantAllocationPrimaryKey.PrimaryKeyValue}; has it been deleted?");
            }

            var taxonomyLevel = MultiTenantHelpers.GetTaxonomyLevel();
            var grantAllocationBasicsViewData         = new GrantAllocationBasicsViewData(grantAllocation, false, taxonomyLevel);
            var userHasEditGrantAllocationPermissions = new GrantAllocationEditAsAdminFeature().HasPermissionByPerson(CurrentPerson);
            var grantAllocationNotesViewData          = new EntityNotesViewData(
                EntityNote.CreateFromEntityNote(new List <IEntityNote>(grantAllocation.GrantAllocationNotes)),
                SitkaRoute <GrantAllocationController> .BuildUrlFromExpression(x => x.NewGrantAllocationNote(grantAllocationPrimaryKey)),
                grantAllocation.GrantAllocationName,
                userHasEditGrantAllocationPermissions);
            var grantAllocationNoteInternalsViewData = new EntityNotesViewData(
                EntityNote.CreateFromEntityNote(new List <IEntityNote>(grantAllocation.GrantAllocationNoteInternals)),
                SitkaRoute <GrantAllocationController> .BuildUrlFromExpression(x => x.NewGrantAllocationNoteInternal(grantAllocationPrimaryKey)),
                grantAllocation.GrantAllocationName,
                userHasEditGrantAllocationPermissions);

            var costTypes = CostType.All.Where(x => x.IsValidInvoiceLineItemCostType).OrderBy(x => x.CostTypeDisplayName).ToList();

            const string chartTitle       = "Grant Allocation Expenditures";
            var          chartContainerID = chartTitle.Replace(" ", "");

            // If ProjectGrantAllocationExpenditures is empty, ToGoogleChart returns null...
            var googleChart = grantAllocation.GrantAllocationExpenditures
                              .ToGoogleChart(x => x.CostType?.CostTypeDisplayName,
                                             costTypes.Select(x => x.CostTypeDisplayName).ToList(),
                                             x => x.CostType?.CostTypeDisplayName,
                                             chartContainerID,
                                             grantAllocation.DisplayName);

            // Which makes this guy bork (bork bork bork)
            googleChart?.GoogleChartConfiguration.Legend.SetLegendPosition(GoogleChartLegendPosition.Top);
            var viewGoogleChartViewData = new ViewGoogleChartViewData(googleChart, chartTitle, 350, false);

            var projectGrantAllocationRequestsGridSpec = new ProjectGrantAllocationRequestsGridSpec()
            {
                ObjectNameSingular  = "Project",
                ObjectNamePlural    = "Projects",
                SaveFiltersInCookie = true
            };

            var grantAllocationExpendituresGridSpec = new GrantAllocationExpendituresGridSpec();
            var grantAllocationAwardsGridSpec       = new GrantAllocationAwardGridSpec(CurrentPerson, grantAllocation);

            var viewData = new Views.GrantAllocation.DetailViewData(CurrentPerson, grantAllocation, grantAllocationBasicsViewData, grantAllocationNotesViewData, grantAllocationNoteInternalsViewData, viewGoogleChartViewData, projectGrantAllocationRequestsGridSpec, grantAllocationExpendituresGridSpec, grantAllocationAwardsGridSpec);

            return(RazorView <Views.GrantAllocation.Detail, Views.GrantAllocation.DetailViewData>(viewData));
        }