Skip to content

Commit

Permalink
BA-1069 - Fix more opp code smells (eliminate dupes)
Browse files Browse the repository at this point in the history
  • Loading branch information
sutherlanda committed Mar 27, 2019
1 parent 9cc1b62 commit d486cfa
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 57 deletions.
25 changes: 9 additions & 16 deletions modules/opportunities/client/config/OpportunityRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { IAuthenticationService } from '../../../users/client/services/Authentic
import { IOpportunitiesService, IOpportunityResource } from '../services/OpportunitiesService';

export default class OpportunityRouter {
public static $inject = ['$stateProvider'];

private rootState: Ng1StateDeclaration = {
abstract: true,
Expand Down Expand Up @@ -50,11 +49,7 @@ export default class OpportunityRouter {
opportunity: [
'$stateParams',
'OpportunitiesService',
async ($stateParams: StateParams, OpportunitiesService: IOpportunitiesService): Promise<IOpportunityResource> => {
return await OpportunitiesService.get({
opportunityId: $stateParams.opportunityId
}).$promise;
}
this.resolveOpportunity
],
myproposal: [
'$stateParams',
Expand Down Expand Up @@ -89,11 +84,7 @@ export default class OpportunityRouter {
opportunity: [
'$stateParams',
'OpportunitiesService',
async ($stateParams: StateParams, OpportunitiesService: IOpportunitiesService): Promise<IOpportunityResource> => {
return await OpportunitiesService.get({
opportunityId: $stateParams.opportunityId
}).$promise;
}
this.resolveOpportunity
],
org: [
'AuthenticationService',
Expand Down Expand Up @@ -169,11 +160,7 @@ export default class OpportunityRouter {
opportunity: [
'$stateParams',
'OpportunitiesService',
async ($stateParams: StateParams, OpportunitiesService: IOpportunitiesService): Promise<IOpportunityResource> => {
return await OpportunitiesService.get({
opportunityId: $stateParams.opportunityId
}).$promise;
}
this.resolveOpportunity
]
}
};
Expand Down Expand Up @@ -316,6 +303,12 @@ export default class OpportunityRouter {
this.$stateProvider.state('createswu', this.createSWUState);
this.$stateProvider.state('oppcreatelanding', this.createLandingState);
}

private async resolveOpportunity($stateParams: StateParams, OpportunitiesService: IOpportunitiesService): Promise<IOpportunityResource> {
return await OpportunitiesService.get({
opportunityId: $stateParams.opportunityId
}).$promise;
}
}

angular.module('opportunities.routes').config(['$stateProvider', ($stateProvider: StateProvider) => new OpportunityRouter($stateProvider)]);
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import angular, { IController, IScope, uiNotification } from 'angular';
import angular, { IController, IScope, ui, uiNotification } from 'angular';
import _ from 'lodash';
import { ICapabilitySkill } from '../../../capabilities/shared/ICapabilitySkillDTO';
import { IProposalResource, IProposalService } from '../../../proposals/client/services/ProposalService';
Expand All @@ -14,6 +14,13 @@ interface IEvaluationScope extends IScope {
opportunity: IOpportunityResource;
}

interface IEvalModalScope {
proposals: IProposalResource[];
maxPoints: number;
cancel(): void;
save(): Promise<void>;
}

enum Stages {
NEW = 0,
REVIEW,
Expand Down Expand Up @@ -321,13 +328,6 @@ export class OpportunityEvaluationDirectiveController implements IController {
}

public async openCodeChallengeModal(): Promise<void> {
interface ICodeChallengeModalScope {
proposals: IProposalResource[];
maxCodeChallengePoints: number;
cancel(): void;
save(): Promise<void>;
}

const modalResponse = await this.modalService.showModal(
{
size: 'sm',
Expand All @@ -336,23 +336,16 @@ export class OpportunityEvaluationDirectiveController implements IController {
controller: [
'$scope',
'$uibModalInstance',
($scope: ICodeChallengeModalScope, $uibModalInstance: ng.ui.bootstrap.IModalInstanceService) => {
($scope: IEvalModalScope, $uibModalInstance: ng.ui.bootstrap.IModalInstanceService) => {
$scope.proposals = angular.copy(this.proposals);
$scope.maxCodeChallengePoints = this.opportunity.weights.codechallenge * this.maximumScore;
$scope.maxPoints = this.opportunity.weights.codechallenge * this.maximumScore;

$scope.cancel = (): void => {
$uibModalInstance.close({});
};

$scope.save = async (): Promise<void> => {
const message = 'Are you sure you wish to commit the code challenge scores as entered?';
const choice = await this.ask.yesNo(message);
if (choice) {
$uibModalInstance.close({
action: 'save',
proposalsToSave: $scope.proposals
});
}
this.confirmModalSave('Are you sure you wish to commit the code challenge scores as entered?', $uibModalInstance, $scope);
};
}
]
Expand Down Expand Up @@ -393,13 +386,6 @@ export class OpportunityEvaluationDirectiveController implements IController {
* Validates based on interview weighting and max points
*/
public async openInterviewModal(): Promise<void> {
interface IInterviewModalScope {
proposals: IProposalResource[];
maxInterviewPoints: number;
cancel(): void;
save(): Promise<void>;
}

const modalResponse = await this.modalService.showModal(
{
size: 'sm',
Expand All @@ -408,23 +394,16 @@ export class OpportunityEvaluationDirectiveController implements IController {
controller: [
'$scope',
'$uibModalInstance',
($scope: IInterviewModalScope, $uibModalInstance: ng.ui.bootstrap.IModalInstanceService) => {
($scope: IEvalModalScope, $uibModalInstance: ng.ui.bootstrap.IModalInstanceService) => {
$scope.proposals = angular.copy(this.proposals);
$scope.maxInterviewPoints = this.opportunity.weights.interview * this.maximumScore;
$scope.maxPoints = this.opportunity.weights.interview * this.maximumScore;

$scope.cancel = (): void => {
$uibModalInstance.close({});
};

$scope.save = async (): Promise<void> => {
const message = 'Are you sure you wish to commit the team scenario scores as entered?';
const choice = await this.ask.yesNo(message);
if (choice) {
$uibModalInstance.close({
action: 'save',
proposalsToSave: $scope.proposals
});
}
$scope.save = async () => {
this.confirmModalSave('Are you sure you wish to commit the team scenario scores as entered?', $uibModalInstance, $scope);
};
}
]
Expand Down Expand Up @@ -752,8 +731,18 @@ export class OpportunityEvaluationDirectiveController implements IController {
}
}

private async confirmModalSave(message: string, modalInstance: ui.bootstrap.IModalServiceInstance, scope: IEvalModalScope): Promise<void> {
const choice = await this.ask.yesNo(message);
if (choice) {
modalInstance.close({
action: 'save',
proposalsToSave: scope.proposals
});
}
}

private handleError(error: any): void {
const errorMessage = (error as any).data ? (error as any).data.message : error.message;
const errorMessage = error.data ? error.data.message : error.message;
this.Notification.error({
title: 'Error',
message: `<i class="fas fa-exclamation-triangle"></i> ${errorMessage}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ <h5>Code Challenge Scores</h5>
<div class="row my-2 mx-auto" ng-repeat="proposal in proposals" ng-if="proposal.screenedIn">
<div class="col"></div>
<div class="col-2 pr-0">
<input class="scoreBox" name="input" type="number" min="0" max="{{ maxCodeChallengePoints }}" ng-model="proposal.scores.codechallenge" onclick="this.select()" />
<input class="scoreBox" name="input" type="number" min="0" max="{{ maxPoints }}" ng-model="proposal.scores.codechallenge" onclick="this.select()" />
</div>
<div class="col pl-0 text-left">
{{proposal.businessName | limitTo: 20 }}{{ proposal.businessName.length > 20 ? '...' : '' }}
Expand All @@ -21,7 +21,7 @@ <h5>Code Challenge Scores</h5>

</div>
<div class="my-3">
<div>Scores must be a number between 0 and {{ maxCodeChallengePoints }}</div>
<div>Scores must be a number between 0 and {{ maxPoints }}</div>
<button ng-disabled="!scoreForm.$valid || scoreForm.$error.number" class="btn btn-primary float-right" data-ng-click="save()"><i
class="fas fa-lock"></i> Lock in Scores</button>
<button class="btn btn-default float-right" data-ng-click="cancel()">Cancel</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ <h5>Interview Scores</h5>
<div class="row my-2 mx-auto" ng-repeat="proposal in proposals" ng-if="proposal.passedCodeChallenge">
<div class="col"></div>
<div class="col-2 pr-0">
<input class="scoreBox" name="input" type="number" min="0" max="{{ maxInterviewPoints }}" ng-model="proposal.scores.interview" onclick="this.select()" />
<input class="scoreBox" name="input" type="number" min="0" max="{{ maxPoints }}" ng-model="proposal.scores.interview" onclick="this.select()" />
</div>
<div class="col pl-0 text-left">
{{proposal.businessName | limitTo: 20 }}{{ proposal.businessName.length > 20 ? '...' : '' }}
Expand All @@ -17,7 +17,7 @@ <h5>Interview Scores</h5>
</form>

<div class="my-3">
<div>Scores must be a number between 0 and {{ maxInterviewPoints }}</div>
<div>Scores must be a number between 0 and {{ maxPoints }}</div>
<button ng-disabled="!scoreForm.$valid || scoreForm.$error.number" class="btn btn-primary float-right" data-ng-click="save()"><i
class="fas fa-lock"></i> Lock in Scores</button>
<button class="btn btn-default float-right" data-ng-click="cancel()">Cancel</button>
Expand Down

0 comments on commit d486cfa

Please sign in to comment.