Пример #1
0
        public DetailViewData(Person currentPerson, Models.Agreement agreement, bool userHasEditAgreementPermissions)
            : base(currentPerson, null)
        {
            Agreement            = agreement;
            HtmlPageTitle        = agreement.AgreementTitle;
            EntityName           = $"{Models.FieldDefinition.Agreement.GetFieldDefinitionLabel()}";
            EditAgreementUrl     = agreement.GetEditUrl();
            BackToAgreementsText = "Back to all Agreements";
            AgreementsListUrl    = SitkaRoute <AgreementController> .BuildUrlFromExpression(c => c.Index());

            PageTitle       = agreement.AgreementTitle.ToEllipsifiedStringClean(110);
            BreadCrumbTitle = $"{Models.FieldDefinition.Agreement.GetFieldDefinitionLabel()} Detail";
            UserHasEditAgreementPermissions = userHasEditAgreementPermissions;
            // Used for creating file download link, if file available
            ShowDownload = agreement.AgreementFileResource != null;

            ProgramIndices = agreement.ProgramIndices;
            ProjectCodes   = agreement.ProjectCodes;

            AgreementPersonGridSpec = new AgreementPersonGridSpec(currentPerson)
            {
                ObjectNameSingular = "Agreement Contact", ObjectNamePlural = "Agreement Contacts", SaveFiltersInCookie = true
            };

            if (UserHasEditAgreementPermissions)
            {
                var contentUrl = SitkaRoute <AgreementController> .BuildUrlFromExpression(t => t.NewAgreementPerson(agreement.AgreementID));

                AgreementPersonGridSpec.CreateEntityModalDialogForm = new ModalDialogForm(contentUrl, "Create a new Agreement Contact");
                EditAgreementGrantAllocationRelationshipsUrl        = SitkaRoute <AgreementController> .BuildUrlFromExpression(t => t.EditAgreementGrantAllocationRelationships(agreement.AgreementID));
            }

            AgreementPersonGridName    = "agreementPersonGrid";
            AgreementPersonGridDataUrl = SitkaRoute <AgreementController> .BuildUrlFromExpression(ac => ac.AgreementPersonGridJsonData(agreement.AgreementID));

            List <AgreementGrantAllocation> agreementGrantAllocationsList = agreement.AgreementGrantAllocations.ToList();

            CurrentAgreementGrantAllocationsInSortedOrder = AgreementGrantAllocation.OrderAgreementGrantAllocationsByYearPrefixedGrantNumbersThenEverythingElse(agreementGrantAllocationsList);
            AgreementProjectsByGrantAllocations           = ProjectAgreementByGrantAllocation.MakeAgreementProjectsByGrantAllocation(agreementGrantAllocationsList);
        }
        public DetailViewData(Person currentPerson, Models.Project project, List <ProjectStage> projectStages,
                              ProjectBasicsViewData projectBasicsViewData, ProjectAttributesViewData projectAttributesViewData,
                              ProjectLocationSummaryViewData projectLocationSummaryViewData,
                              ProjectFundingDetailViewData projectFundingDetailViewData,
                              PerformanceMeasureExpectedSummaryViewData performanceMeasureExpectedSummaryViewData,
                              PerformanceMeasureReportedValuesGroupedViewData performanceMeasureReportedValuesGroupedViewData,
                              ProjectExpendituresDetailViewData projectExpendituresDetailViewData,
                              ImageGalleryViewData imageGalleryViewData, EntityNotesViewData projectNotesViewData,
                              EntityNotesViewData internalNotesViewData,
                              EntityExternalLinksViewData entityExternalLinksViewData,
                              ProjectBasicsTagsViewData projectBasicsTagsViewData, bool userHasProjectAdminPermissions,
                              bool userHasEditProjectPermissions, bool userHasProjectUpdatePermissions,
                              bool userHasPerformanceMeasureActualManagePermissions, string mapFormID,
                              string editSimpleProjectLocationUrl, string editDetailedProjectLocationUrl,
                              string editProjectOrganizationsUrl, string editPerformanceMeasureExpectedsUrl,
                              string editPerformanceMeasureActualsUrl, string editReportedExpendituresUrl,
                              AuditLogsGridSpec auditLogsGridSpec, string auditLogsGridDataUrl,
                              string editExternalLinksUrl, ProjectNotificationGridSpec projectNotificationGridSpec,
                              string projectNotificationGridName, string projectNotificationGridDataUrl, bool userCanEditProposal,
                              ProjectOrganizationsDetailViewData projectOrganizationsDetailViewData,
                              List <Models.ClassificationSystem> classificationSystems,
                              string editProjectBoundingBoxFormID, ProjectPeopleDetailViewData projectPeopleDetailViewData,
                              TreatmentAreaGridSpec treatmentAreaGridSpec,
                              string treatmentAreaGridDataUrl
                              , TreatmentGridSpec treatmentGridSpec
                              , string treatmentGridDataUrl
                              , string editProjectRegionUrl
                              , string editProjectPriorityLandscapeUrl,
                              InteractionEventGridSpec projectInteractionEventsGridSpec, string projectInteractionEventsGridDataUrl)
            : base(currentPerson, project)
        {
            PageTitle       = project.DisplayName.ToEllipsifiedStringClean(110);
            BreadCrumbTitle = $"{Models.FieldDefinition.Project.GetFieldDefinitionLabel()} Detail";

            ProjectStages = projectStages;

            EditProjectUrl = project.GetEditUrl();

            EditProjectAttributesUrl = project.GetEditProjectAttributesUrl();

            CanViewProjectFactSheet = ProjectController.FactSheetIsAvailable(project);

            UserHasProjectAdminPermissions = userHasProjectAdminPermissions;
            UserHasEditProjectPermissions  = userHasEditProjectPermissions;
            UserHasPerformanceMeasureActualManagePermissions = userHasPerformanceMeasureActualManagePermissions;

            var projectAlerts          = new List <string>();
            var proposedProjectListUrl = SitkaRoute <ProjectController> .BuildUrlFromExpression(c => c.Proposed());

            var backToAllProposalsText = "Back to all Applications";
            var pendingProjectsListUrl = SitkaRoute <ProjectController> .BuildUrlFromExpression(c => c.Pending());

            var backToAllPendingProjectsText = $"Back to all Pending {Models.FieldDefinition.Project.GetFieldDefinitionLabelPluralized()}";

            if (project.IsRejected())
            {
                var projectApprovalStatus = project.ProjectApprovalStatus;
                ProjectUpdateButtonText =
                    projectApprovalStatus == ProjectApprovalStatus.Draft ||
                    projectApprovalStatus == ProjectApprovalStatus.Returned
                        ? $"Edit Pending {Models.FieldDefinition.Project.GetFieldDefinitionLabel()}"
                        : $"Review Pending {Models.FieldDefinition.Project.GetFieldDefinitionLabel()}";
                ProjectWizardUrl =
                    SitkaRoute <ProjectCreateController> .BuildUrlFromExpression(x => x.EditBasics(project.ProjectID));

                CanLaunchProjectOrProposalWizard = userCanEditProposal;
                if (project.IsProposal())
                {
                    ProjectListUrl     = proposedProjectListUrl;
                    BackToProjectsText = backToAllProposalsText;
                }
                else if (project.IsPendingProject())
                {
                    ProjectListUrl     = pendingProjectsListUrl;
                    BackToProjectsText = backToAllPendingProjectsText;
                }

                if (userHasProjectAdminPermissions || currentPerson.CanStewardProject(project))
                {
                    projectAlerts.Add(
                        $"This {Models.FieldDefinition.Project.GetFieldDefinitionLabel()} was rejected and can no longer be edited. It can be deleted, or preserved for archival purposes.");
                }
            }
            else if (project.IsProposal())
            {
                var projectApprovalStatus = project.ProjectApprovalStatus;
                ProjectUpdateButtonText =
                    projectApprovalStatus == ProjectApprovalStatus.Draft ||
                    projectApprovalStatus == ProjectApprovalStatus.Returned
                        ? "Edit Application"
                        : "Review Application";
                ProjectWizardUrl =
                    SitkaRoute <ProjectCreateController> .BuildUrlFromExpression(x => x.EditBasics(project.ProjectID));

                CanLaunchProjectOrProposalWizard = userCanEditProposal;
                ProjectListUrl     = proposedProjectListUrl;
                BackToProjectsText = backToAllProposalsText;
                if (userHasProjectAdminPermissions || currentPerson.CanStewardProject(project))
                {
                    projectAlerts.Add(
                        $"This {Models.FieldDefinition.Project.GetFieldDefinitionLabel()} is in the {Models.FieldDefinition.Application.GetFieldDefinitionLabel()} stage. Any edits to this {Models.FieldDefinition.Project.GetFieldDefinitionLabel()} must be made using the Add New {Models.FieldDefinition.Project.GetFieldDefinitionLabel()} workflow.");
                }
            }
            else if (project.IsPendingProject())
            {
                var projectApprovalStatus = project.ProjectApprovalStatus;
                ProjectUpdateButtonText =
                    projectApprovalStatus == ProjectApprovalStatus.Draft ||
                    projectApprovalStatus == ProjectApprovalStatus.Returned
                        ? $"Edit Pending {Models.FieldDefinition.Project.GetFieldDefinitionLabel()}"
                        : $"Review Pending {Models.FieldDefinition.Project.GetFieldDefinitionLabel()}";
                ProjectWizardUrl =
                    SitkaRoute <ProjectCreateController> .BuildUrlFromExpression(x => x.EditBasics(project.ProjectID));

                CanLaunchProjectOrProposalWizard = userCanEditProposal;
                ProjectListUrl     = pendingProjectsListUrl;
                BackToProjectsText = backToAllPendingProjectsText;
                if (userHasProjectAdminPermissions || currentPerson.CanStewardProject(project))
                {
                    projectAlerts.Add(
                        $"This {Models.FieldDefinition.Project.GetFieldDefinitionLabel()} is pending. Any edits to this {Models.FieldDefinition.Project.GetFieldDefinitionLabel()} must be made using the Add New {Models.FieldDefinition.Project.GetFieldDefinitionLabel()} workflow.");
                }
            }
            else
            {
                var latestUpdateState = project.GetLatestUpdateState();
                ProjectUpdateButtonText =
                    latestUpdateState == ProjectUpdateState.Submitted ||
                    latestUpdateState == ProjectUpdateState.Returned
                        ? "Review Update"
                        : $"Update {Models.FieldDefinition.Project.GetFieldDefinitionLabel()}";
                ProjectWizardUrl = project.GetProjectUpdateUrl();
                CanLaunchProjectOrProposalWizard = userHasProjectUpdatePermissions;
                ProjectListUrl     = FullProjectListUrl;
                BackToProjectsText = $"Back to all {Models.FieldDefinition.Project.GetFieldDefinitionLabelPluralized()}";


                if (currentPerson.PersonIsProjectOwnerWhoCanStewardProjects)
                {
                    if (currentPerson.CanStewardProject(project))
                    {
                        projectAlerts.Add(
                            $"You are a {Models.FieldDefinition.ProjectSteward.GetFieldDefinitionLabel()} for this {Models.FieldDefinition.Project.GetFieldDefinitionLabel()}. You may edit this {Models.FieldDefinition.Project.GetFieldDefinitionLabel()} by using the <i class=\"glyphicon glyphicon-edit\"></i> icon on each panel.<br/>");
                    }
                    else
                    {
                        projectAlerts.Add(
                            $"You are a {Models.FieldDefinition.ProjectSteward.GetFieldDefinitionLabel()}, but not for this {Models.FieldDefinition.Project.GetFieldDefinitionLabel()}. You may only edit {Models.FieldDefinition.Project.GetFieldDefinitionLabelPluralized()} that are associated with your {Models.FieldDefinition.ProjectStewardshipArea.GetFieldDefinitionLabel()}.");
                    }
                }
            }


            if (project.GetLatestNotApprovedUpdateBatch() != null)
            {
                if (userHasProjectAdminPermissions || currentPerson.CanStewardProject(project))
                {
                    projectAlerts.Add($"This {Models.FieldDefinition.Project.GetFieldDefinitionLabel()} has an Update in progress. Changes made through this page will be overwritten when the Update is approved.");
                }
                else
                {
                    projectAlerts.Add($"This {Models.FieldDefinition.Project.GetFieldDefinitionLabel()} has an Update in progress.");
                }
            }

            ProjectAlerts = projectAlerts;

            ProjectBasicsViewData     = projectBasicsViewData;
            ProjectBasicsTagsViewData = projectBasicsTagsViewData;

            ProjectLocationSummaryViewData = projectLocationSummaryViewData;
            MapFormID = mapFormID;
            EditSimpleProjectLocationUrl    = editSimpleProjectLocationUrl;
            EditDetailedProjectLocationUrl  = editDetailedProjectLocationUrl;
            EditProjectRegionUrl            = editProjectRegionUrl;
            EditProjectPriorityLandscapeUrl = editProjectPriorityLandscapeUrl;

            EditProjectBoundingBoxUrl = SitkaRoute <ProjectLocationController> .BuildUrlFromExpression(c => c.EditProjectBoundingBox(project));

            EditProjectBoundingBoxFormID = editProjectBoundingBoxFormID;
            ProjectAttributesViewData    = projectAttributesViewData;

            EditProjectOrganizationsUrl = editProjectOrganizationsUrl;

            PerformanceMeasureExpectedSummaryViewData = performanceMeasureExpectedSummaryViewData;
            EditPerformanceMeasureExpectedsUrl        = editPerformanceMeasureExpectedsUrl;

            PerformanceMeasureReportedValuesGroupedViewData = performanceMeasureReportedValuesGroupedViewData;
            EditPerformanceMeasureActualsUrl = editPerformanceMeasureActualsUrl;

            ProjectFundingDetailViewData = projectFundingDetailViewData;
            EditExpectedFundingUrl       =
                SitkaRoute <ProjectGrantAllocationRequestController> .BuildUrlFromExpression(c =>
                                                                                             c.EditProjectGrantAllocationRequestsForProject(project));

            ProjectExpendituresDetailViewData = projectExpendituresDetailViewData;
            EditReportedExpendituresUrl       = editReportedExpendituresUrl;
            ProjectPeopleDetailViewData       = projectPeopleDetailViewData;
            EditExternalLinksUrl = editExternalLinksUrl;
            ImageGalleryViewData = imageGalleryViewData;

            ProjectNotesViewData  = projectNotesViewData;
            InternalNotesViewData = internalNotesViewData;

            EntityExternalLinksViewData = entityExternalLinksViewData;

            ProjectUpdateBatchGridSpec = new ProjectUpdateBatchGridSpec
            {
                ObjectNameSingular  = $"{Models.FieldDefinition.Project.GetFieldDefinitionLabel()} Update",
                ObjectNamePlural    = $"{Models.FieldDefinition.Project.GetFieldDefinitionLabel()} Updates",
                SaveFiltersInCookie = true
            };
            ProjectUpdateBatchGridName    = "projectUpdateBatch";
            ProjectUpdateBatchGridDataUrl =
                SitkaRoute <ProjectController> .BuildUrlFromExpression(x =>
                                                                       x.ProjectUpdateBatchGridJsonData(project.ProjectID));

            AuditLogsGridSpec    = auditLogsGridSpec;
            AuditLogsGridName    = "projectAuditLogsGrid";
            AuditLogsGridDataUrl = auditLogsGridDataUrl;

            ProjectNotificationGridSpec        = projectNotificationGridSpec;
            ProjectNotificationGridName        = projectNotificationGridName;
            ProjectNotificationGridDataUrl     = projectNotificationGridDataUrl;
            ProjectOrganizationsDetailViewData = projectOrganizationsDetailViewData;

            EditProjectPriorityLandscapeFormID = ProjectPriorityLandscapeController.GetEditProjectPriorityLandscapesFormID();
            EditProjectRegionFormID            = ProjectRegionController.GetEditProjectRegionsFormID();

            ProjectStewardCannotEditUrl =
                SitkaRoute <ProjectController> .BuildUrlFromExpression(c => c.ProjectStewardCannotEdit());

            ProjectStewardCannotEditPendingApprovalUrl =
                SitkaRoute <ProjectController> .BuildUrlFromExpression(c =>
                                                                       c.ProjectStewardCannotEditPendingApproval(project));

            ClassificationSystems = classificationSystems;

            ProjectCostShareViewData = new ProjectCostShareViewData(project, currentPerson);

            ProjectDocumentsDetailViewData = new ProjectDocumentsDetailViewData(
                EntityDocument.CreateFromEntityDocument(new List <IEntityDocument>(project.ProjectDocuments)),
                SitkaRoute <ProjectDocumentController> .BuildUrlFromExpression(x => x.New(project)), project.ProjectName,
                new ProjectEditAsAdminFeature().HasPermission(currentPerson, project).HasPermission);

            EditProjectPeopleUrl =
                SitkaRoute <ProjectPersonController> .BuildUrlFromExpression(x => x.EditPeople(project));

            TreatmentAreaGridSpec    = treatmentAreaGridSpec;
            TreatmentAreaGrid        = "treatmentAreaGrid";
            TreatmentAreaGridDataUrl = treatmentAreaGridDataUrl;


            TreatmentGridSpec    = treatmentGridSpec;
            TreatmentGrid        = "treatmentGrid";
            TreatmentGridDataUrl = treatmentGridDataUrl;

            ProjectInteractionEventsGridSpec    = projectInteractionEventsGridSpec;
            ProjectInteractionEventsGridName    = "projectInteractionEventsGrid";
            ProjectInteractionEventsGridDataUrl = projectInteractionEventsGridDataUrl;

            ProjectAgreementByGrantAllocations = ProjectAgreementByGrantAllocation.MakeAgreementProjectsByGrantAllocation(Project.ProjectGrantAllocationRequests.ToList());
        }