Merge pull request #277 from finnlabs/housekeeping/ts-strictness

Adapt to stricter core
pull/6827/head
Oliver Günther 8 years ago committed by GitHub
commit 63fad93453
  1. 20
      frontend/app/components/budget/cost-budget-subform.directive.ts
  2. 12
      frontend/app/components/budget/cost-unit-subform.directive.ts
  3. 9
      frontend/app/components/subform/cost-subform.directive.ts
  4. 14
      frontend/app/components/wp-display/field-types/wp-display-costs-by-type-field.module.ts
  5. 2
      frontend/app/components/wp-display/field-types/wp-display-currency-field.module.ts

@ -25,6 +25,7 @@
// //
// See doc/COPYRIGHT.rdoc for more details. // See doc/COPYRIGHT.rdoc for more details.
// ++ // ++
import {WorkPackageNotificationService} from 'core-components/wp-edit/wp-notification.service';
/*eslint no-eval: "error"*/ /*eslint no-eval: "error"*/
export class CostBudgetSubformController { export class CostBudgetSubformController {
@ -44,7 +45,9 @@ export class CostBudgetSubformController {
// Updater URL for the rows contained here // Updater URL for the rows contained here
public updateUrl: string; public updateUrl: string;
constructor(public $element, public $http, public wpNotificationsService) { constructor(public $element:ng.IAugmentedJQuery,
public $http:ng.IHttpService,
public wpNotificationsService:WorkPackageNotificationService) {
this.container = $element.find('.budget-item-container'); this.container = $element.find('.budget-item-container');
this.rowIndex = parseInt(this.itemCount); this.rowIndex = parseInt(this.itemCount);
@ -68,7 +71,7 @@ export class CostBudgetSubformController {
/** /**
* Refreshes the given row after updating values * Refreshes the given row after updating values
*/ */
public refreshRow(row_identifier) { public refreshRow(row_identifier:string) {
var row = this.$element.find('#' + row_identifier); var row = this.$element.find('#' + row_identifier);
var request = this.buildRefreshRequest(row, row_identifier); var request = this.buildRefreshRequest(row, row_identifier);
@ -77,7 +80,7 @@ export class CostBudgetSubformController {
method: 'POST', method: 'POST',
data: request, data: request,
headers: { 'Accept': 'application/javascript' } headers: { 'Accept': 'application/javascript' }
}).then(response => { }).then((response:any) => {
eval(response.data); eval(response.data);
}).catch(response => { }).catch(response => {
this.wpNotificationsService.handleErrorResponse(response); this.wpNotificationsService.handleErrorResponse(response);
@ -103,14 +106,14 @@ export class CostBudgetSubformController {
/** /**
* Returns the params for the update request * Returns the params for the update request
*/ */
private buildRefreshRequest(row, row_identifier) { private buildRefreshRequest(row:JQuery, row_identifier:string) {
var request = { var request:any = {
element_id: row_identifier, element_id: row_identifier,
fixed_date: angular.element('#cost_object_fixed_date').val() fixed_date: angular.element('#cost_object_fixed_date').val()
}; };
// Augment common values with specific values for this type // Augment common values with specific values for this type
row.find('.budget-item-value').each((_i, el) => { row.find('.budget-item-value').each((_i:number, el:HTMLElement) => {
var field = angular.element(el); var field = angular.element(el);
request[field.data('requestKey')] = field.val(); request[field.data('requestKey')] = field.val();
}); });
@ -126,7 +129,10 @@ function costsBudgetSubform() {
updateUrl: '@', updateUrl: '@',
itemCount: '@' itemCount: '@'
}, },
link: (scope, element, attr, ctrl) => { link: (scope:ng.IScope,
element:ng.IAugmentedJQuery,
attr:ng.IAttributes,
ctrl:any) => {
const template = element.find('.budget-row-template'); const template = element.find('.budget-row-template');
ctrl.rowTemplate = template[0].outerHTML; ctrl.rowTemplate = template[0].outerHTML;
template.remove(); template.remove();

@ -31,32 +31,32 @@ export class CostUnitSubformController {
public objId: string; public objId: string;
public objName: string; public objName: string;
constructor(public $element) { constructor(public $element:ng.IAugmentedJQuery) {
// Add new row handler // Add new row handler
$element.find('#'+this.objId).click(() => { $element.find('#'+this.objId).click(() => {
this.makeEditable('#'+this.objId, this.objName); this.makeEditable('#'+this.objId, this.objName);
}); });
} }
private getCurrencyValue(str) { private getCurrencyValue(str:string) {
var result = str.match(/^\s*(([0-9]+[.,])+[0-9]+) (.+)\s*/); var result = str.match(/^\s*(([0-9]+[.,])+[0-9]+) (.+)\s*/);
return result ? new Array(result[1], result[3]) : new Array(str, ""); return result ? new Array(result[1], result[3]) : new Array(str, "");
} }
public makeEditable(id, name){ public makeEditable(id:string, name:string){
var obj = jQuery(id); var obj = jQuery(id);
jQuery(id).click(this.edit_and_focus(obj, name)); jQuery(id).click(this.edit_and_focus(obj, name));
} }
private edit_and_focus(obj, name) { private edit_and_focus(obj:any, name:string) {
this.edit(obj, name); this.edit(obj, name);
jQuery('#'+obj[0].id+'_edit').focus(); jQuery('#'+obj[0].id+'_edit').focus();
jQuery('#'+obj[0].id+'_edit').select(); jQuery('#'+obj[0].id+'_edit').select();
} }
private edit(obj, name, obj_value?:any) { private edit(obj:any, name:string, obj_value?:any) {
obj.hide(); obj.hide();
var obj_value = typeof(obj_value) != 'undefined' ? obj_value : obj[0].innerHTML; var obj_value = typeof(obj_value) != 'undefined' ? obj_value : obj[0].innerHTML;
@ -85,7 +85,7 @@ export class CostUnitSubformController {
}); });
} }
private cleanUp(obj){ private cleanUp(obj:any){
jQuery('#'+obj[0].id+'_section').remove(); jQuery('#'+obj[0].id+'_section').remove();
obj.show(); obj.show();
} }

@ -40,11 +40,11 @@ export class CostSubformController {
// subform item count as output by rails // subform item count as output by rails
public itemCount: string; public itemCount: string;
constructor(public $element) { constructor(public $element:ng.IAugmentedJQuery) {
this.container = $element.find('.subform-container'); this.container = $element.find('.subform-container');
this.rowIndex = parseInt(this.itemCount); this.rowIndex = parseInt(this.itemCount);
$element.on('click', '.delete-row-button', (evt) => { $element.on('click', '.delete-row-button', (evt:JQueryEventObject) => {
var row = angular.element(evt.target).closest('.subform-row'); var row = angular.element(evt.target).closest('.subform-row');
row.remove(); row.remove();
}); });
@ -78,7 +78,10 @@ function costsSubform() {
return { return {
restrict: 'E', restrict: 'E',
scope: { itemCount: '@' }, scope: { itemCount: '@' },
link: (scope, element, attr, ctrl) => { link: (scope:ng.IScope,
element:ng.IAugmentedJQuery,
attr:ng.IAttributes,
ctrl:any) => {
const template = element.find('.subform-row-template'); const template = element.find('.subform-row-template');
ctrl.rowTemplate = template[0].outerHTML; ctrl.rowTemplate = template[0].outerHTML;
template.remove(); template.remove();

@ -28,8 +28,9 @@
import {DisplayField} from 'core-components/wp-display/wp-display-field/wp-display-field.module'; import {DisplayField} from 'core-components/wp-display/wp-display-field/wp-display-field.module';
import {WorkPackageCacheService} from 'core-components/work-packages/work-package-cache.service'; import {WorkPackageCacheService} from 'core-components/work-packages/work-package-cache.service';
import {HalResource} from 'core-components/api/api-v3/hal-resources/hal-resource.service.ts'; import {HalResource} from 'core-components/api/api-v3/hal-resources/hal-resource.service';
import {WorkPackageResource} from 'core-components/api/api-v3/hal-resources/work-package-resource.service.ts'; import {WorkPackageResource} from 'core-components/api/api-v3/hal-resources/work-package-resource.service';
interface ICostsByType { interface ICostsByType {
$source: { $source: {
@ -44,16 +45,13 @@ interface ICostsByType {
export class CostsByTypeDisplayField extends DisplayField { export class CostsByTypeDisplayField extends DisplayField {
isManualRenderer = true; public wpCacheService:WorkPackageCacheService;
private wpCacheService:WorkPackageCacheService;
constructor(public resource:HalResource, constructor(public resource:HalResource,
public name:string, public name:string,
public schema) { public schema:op.FieldSchema) {
super(resource, name, schema); super(resource, name, schema);
this.wpCacheService = <WorkPackageCacheService> this.$injector.get('wpCacheService');
this.loadIfNecessary(); this.loadIfNecessary();
} }
@ -80,3 +78,5 @@ export class CostsByTypeDisplayField extends DisplayField {
this.value.elements.length === 0; this.value.elements.length === 0;
} }
} }
CostsByTypeDisplayField.$inject = ['wpCacheService'];

@ -30,8 +30,6 @@ import {DisplayField} from 'core-components/wp-display/wp-display-field/wp-displ
export class CurrencyDisplayField extends DisplayField { export class CurrencyDisplayField extends DisplayField {
isManualRenderer = true;
public isEmpty(): boolean { public isEmpty(): boolean {
return !this.value || return !this.value ||
!parseFloat(this.value.split(" ")[0]); !parseFloat(this.value.split(" ")[0]);

Loading…
Cancel
Save