Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PCHR-3459: Add Tool Icon to Edit Job Contract Options #2620

Conversation

ajesamson
Copy link
Contributor

@ajesamson ajesamson commented May 24, 2018

Overview

Provision for editing options while creating record is not available for some Job Contract options. This PR add such facility for Contract Type, Normal Place of Work, Contract End Reason, Revision Change Reason, Location/Standard hours, Pay Scale/Grade, Annual Benefit, Annual Deductions and Plan Type.

Before

before_change_terms

before_correct_error

before_new_contract

After

after_change_terms

after_correct_error

after_new_contract

Technical Details

Tool icon is added next to the input for the specified options. Each tool icon makes a call to the respective controller method for launching and managing associated options.

<div class="col-sm-1 control-label">
  <a class="pointer">
      <i class="crm-i fa-wrench" ng-click="openOptionsEditor('/civicrm/pay_scale?reset=1', 'hrjobcontract_details_contract_type')"></i>
  </a>
</div>

Sample implementation of the controller method (such as openOptionsEditor) is shown below:

function openOptionsEditor (optionUrl, fieldName) {
    var optionTypes = {
      'hrjobcontract_details_contract_type': 'contract_type',
      'hrjobcontract_details_location': 'location',
      'hrjobcontract_details_end_reason': 'end_reason'
    };

    crmAngService.loadForm(optionUrl)
      .on('crmUnload', function () {
        contractDetailsService.getOptions(fieldName, true)
          .then(function (result) {
            $rootScope.options.details[optionTypes[fieldName]] = result.obj;
          });
      });
}

Each crmAngService loadForm method includes a callback to update the dropdown list.

Some other changes were made on Location/Standard hours and Pay Scale / Grade to allow for proper api update via ajax calls. Their templates use data-field value title instead of location and pay_scale respectively.

<tr id="HRPayScale-{$row.id}" class="crm-entity {cycle values="odd-row,even-row"} {$row.class}{if $row.is_active neq 1} disabled{/if}">
  <td class="crm-editable" data-field="pay_scale">{$row.pay_scale}</td>
  <td>{$row.currency}</td>
  <td>{$row.amount}</td>
  <td>{$row.pay_frequency}</td>
  <td id="row_{$row.id}_status">{if $row.is_active eq 1} {ts}Yes{/ts} {else} {ts}No{/ts} {/if}</td>
  <td>{$row.action|replace:'xx':$row.id}</td>
</tr>

Call to API was added for some of the callbacks to have updated changes reflecting.

CRM.api3('HRJobDetails', 'getoptions', {
   'sequential': 1,
   'field': fieldName
}).done(function (data) {
   _.each(data.values, function (option) {
       contractTypes.arr.push({
         key: option.key,
         value: option.value
      });

      contractTypes.obj[option.key] = option.value;
});

The snippet below was removed due to errors when initializing inline edit because of $ being out of scope.

<script type="text/javascript">
    CRM.$('.crm-editable').crmEditable();
  </script>

The inline edit works without this implementation.


✅Manual Tests - passed
✅Jasmine Tests - passed
✅Backstopjs Test - passed
✅JS distributive files - included

@igorpavlov-zz
Copy link
Contributor

igorpavlov-zz commented May 24, 2018

@ajesamson please remove the : from both the PR title and the commit message

@ajesamson ajesamson changed the title :PCHR-3459: Add Tool Icon to Edit Job Contract Options PCHR-3459: Add Tool Icon to Edit Job Contract Options May 24, 2018
@@ -29,6 +29,7 @@ define([
$scope.cancel = cancel;
$scope.dpOpen = dpOpen;
$scope.save = save;
$scope.openRevisionChangeReasonEditor = openRevisionChangeReasonEditor;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please sort aplhabetically

@@ -78,6 +78,11 @@ define([
$scope.cancel = cancel;
$scope.filesValidate = filesValidate;
$scope.save = save;
$scope.openOptionsEditor = openOptionsEditor;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sort alphabetically.

$scope.openHoursLocationOptionsEditor = openHoursLocationOptionsEditor;
$scope.openPayScaleGradeOptionsEditor = openPayScaleGradeOptionsEditor;
$scope.openAnnualBenefitOptionsEditor = openAnnualBenefitOptionsEditor;
$scope.openAnnualDeductionOptionsEditor = openAnnualDeductionOptionsEditor;

// Init
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove that comment, we don't need it as per styleguide

/**
* Opens option editor window for contract type, location, end reason or insurance
*
* @param optionUrl
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The param types are forgotten:

* @param {String} optionUrl
* @param {String} fieldName

if (fieldName === 'hrjobcontract_health_health_plan_type') {
contractHealthService.getOptions(fieldName, true)
.then(function (data) {
var healthOptions = {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use Lodash here:

_.mapValues(_.indexBy([{key: 1, value: 'one'},{key: 2, value: 'two'}], 'key'), 'value')
>>> {1: "one", 2: "two"}

So it would be smth like:

var healthOptions = _.mapValues(_.indexBy(data, 'key'), 'value');

Also, between var x = ... and other types of expressions, like function calls, please leave an empty line break.

function loadAnnualPayOptions (optionType, optionName) {
return OptionGroup.valuesOf(optionType, false)
.then(function (data) {
var options = {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use lodash

'sequential': 1,
'field': fieldName
}).done(function (data) {
_.each(data.values, function (option) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we user lodash's map to create an array and object generation as suggested above?

@@ -86,6 +89,61 @@ define([
});
});

describe('when user clicks on the wrench icon', function () {
locationUrl = '/civicrm/hours_location?reset=1';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we split this into multiple suites? One test is just too large and it is a bit difficult to follow what's going on here.

There should be multiple describes, smth like when user clicks on the "hours location" wrench icon. etc

@@ -457,6 +459,61 @@ define([
});
});

describe('when user clicks on the wrench icon', function () {
locationUrl = '/civicrm/hours_location?reset=1';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

@@ -62,9 +62,6 @@
{/if}
</div>
</div>
<script type="text/javascript">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please leave a description comment in the Tech description of the PR on why are you making this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tech description has been updated.

* @param optionName
* @returns {*}
* @param {String} optionType
* @param {String} optionName
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, why do we remove the return here? Please leave it how it was, but in the documentation it should say what it returns. If it is a {Promise}, then:

```* @return {Promise} resolved with ....`

Same for other places.

@ajesamson ajesamson force-pushed the PCHR-3459-add-tool-icon-to-edit-job-contract-options branch from cf3cf7a to 0e83888 Compare May 25, 2018 11:30
@ajesamson ajesamson force-pushed the PCHR-3459-add-tool-icon-to-edit-job-contract-options branch 3 times, most recently from c2e4a76 to 06ed650 Compare May 25, 2018 13:56
@ajesamson ajesamson force-pushed the PCHR-3459-add-tool-icon-to-edit-job-contract-options branch from 409b296 to ca4980d Compare May 25, 2018 14:40
@ajesamson ajesamson merged commit 2c4921e into PCHR-3162-configurability-changes May 25, 2018
@ajesamson ajesamson deleted the PCHR-3459-add-tool-icon-to-edit-job-contract-options branch May 25, 2018 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants