From 6f99d7290e6bde950603b9355385a6cf970d4ac6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Wed, 15 Feb 2017 21:38:58 +0100 Subject: [PATCH] Adapt to stricter core --- .../budget/cost-budget-subform.directive.ts | 20 ++++++++++++------- .../budget/cost-unit-subform.directive.ts | 12 +++++------ .../subform/cost-subform.directive.ts | 9 ++++++--- .../wp-display-costs-by-type-field.module.ts | 14 ++++++------- .../wp-display-currency-field.module.ts | 2 -- 5 files changed, 32 insertions(+), 25 deletions(-) diff --git a/frontend/app/components/budget/cost-budget-subform.directive.ts b/frontend/app/components/budget/cost-budget-subform.directive.ts index 3ae849ed49..95ed91fb47 100644 --- a/frontend/app/components/budget/cost-budget-subform.directive.ts +++ b/frontend/app/components/budget/cost-budget-subform.directive.ts @@ -25,6 +25,7 @@ // // See doc/COPYRIGHT.rdoc for more details. // ++ +import {WorkPackageNotificationService} from 'core-components/wp-edit/wp-notification.service'; /*eslint no-eval: "error"*/ export class CostBudgetSubformController { @@ -44,7 +45,9 @@ export class CostBudgetSubformController { // Updater URL for the rows contained here 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.rowIndex = parseInt(this.itemCount); @@ -68,7 +71,7 @@ export class CostBudgetSubformController { /** * Refreshes the given row after updating values */ - public refreshRow(row_identifier) { + public refreshRow(row_identifier:string) { var row = this.$element.find('#' + row_identifier); var request = this.buildRefreshRequest(row, row_identifier); @@ -77,7 +80,7 @@ export class CostBudgetSubformController { method: 'POST', data: request, headers: { 'Accept': 'application/javascript' } - }).then(response => { + }).then((response:any) => { eval(response.data); }).catch(response => { this.wpNotificationsService.handleErrorResponse(response); @@ -103,14 +106,14 @@ export class CostBudgetSubformController { /** * Returns the params for the update request */ - private buildRefreshRequest(row, row_identifier) { - var request = { + private buildRefreshRequest(row:JQuery, row_identifier:string) { + var request:any = { element_id: row_identifier, fixed_date: angular.element('#cost_object_fixed_date').val() }; // 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); request[field.data('requestKey')] = field.val(); }); @@ -126,7 +129,10 @@ function costsBudgetSubform() { updateUrl: '@', 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'); ctrl.rowTemplate = template[0].outerHTML; template.remove(); diff --git a/frontend/app/components/budget/cost-unit-subform.directive.ts b/frontend/app/components/budget/cost-unit-subform.directive.ts index d0aad61e1a..bc9c84f89b 100644 --- a/frontend/app/components/budget/cost-unit-subform.directive.ts +++ b/frontend/app/components/budget/cost-unit-subform.directive.ts @@ -31,32 +31,32 @@ export class CostUnitSubformController { public objId: string; public objName: string; - constructor(public $element) { + constructor(public $element:ng.IAugmentedJQuery) { // Add new row handler $element.find('#'+this.objId).click(() => { this.makeEditable('#'+this.objId, this.objName); }); } - private getCurrencyValue(str) { + private getCurrencyValue(str:string) { var result = str.match(/^\s*(([0-9]+[.,])+[0-9]+) (.+)\s*/); 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); 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); jQuery('#'+obj[0].id+'_edit').focus(); jQuery('#'+obj[0].id+'_edit').select(); } - private edit(obj, name, obj_value?:any) { + private edit(obj:any, name:string, obj_value?:any) { obj.hide(); 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(); obj.show(); } diff --git a/frontend/app/components/subform/cost-subform.directive.ts b/frontend/app/components/subform/cost-subform.directive.ts index 1c3dc42642..79b5c4e128 100644 --- a/frontend/app/components/subform/cost-subform.directive.ts +++ b/frontend/app/components/subform/cost-subform.directive.ts @@ -40,11 +40,11 @@ export class CostSubformController { // subform item count as output by rails public itemCount: string; - constructor(public $element) { + constructor(public $element:ng.IAugmentedJQuery) { this.container = $element.find('.subform-container'); 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'); row.remove(); }); @@ -78,7 +78,10 @@ function costsSubform() { return { restrict: 'E', 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'); ctrl.rowTemplate = template[0].outerHTML; template.remove(); diff --git a/frontend/app/components/wp-display/field-types/wp-display-costs-by-type-field.module.ts b/frontend/app/components/wp-display/field-types/wp-display-costs-by-type-field.module.ts index 0afd18a064..be9cd2aef6 100644 --- a/frontend/app/components/wp-display/field-types/wp-display-costs-by-type-field.module.ts +++ b/frontend/app/components/wp-display/field-types/wp-display-costs-by-type-field.module.ts @@ -28,8 +28,9 @@ 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 {HalResource} from 'core-components/api/api-v3/hal-resources/hal-resource.service.ts'; -import {WorkPackageResource} from 'core-components/api/api-v3/hal-resources/work-package-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'; + interface ICostsByType { $source: { @@ -44,16 +45,13 @@ interface ICostsByType { export class CostsByTypeDisplayField extends DisplayField { - isManualRenderer = true; - - private wpCacheService:WorkPackageCacheService; + public wpCacheService:WorkPackageCacheService; constructor(public resource:HalResource, public name:string, - public schema) { + public schema:op.FieldSchema) { super(resource, name, schema); - this.wpCacheService = this.$injector.get('wpCacheService'); this.loadIfNecessary(); } @@ -80,3 +78,5 @@ export class CostsByTypeDisplayField extends DisplayField { this.value.elements.length === 0; } } + +CostsByTypeDisplayField.$inject = ['wpCacheService']; diff --git a/frontend/app/components/wp-display/field-types/wp-display-currency-field.module.ts b/frontend/app/components/wp-display/field-types/wp-display-currency-field.module.ts index 1e0551e68b..f96a936dad 100644 --- a/frontend/app/components/wp-display/field-types/wp-display-currency-field.module.ts +++ b/frontend/app/components/wp-display/field-types/wp-display-currency-field.module.ts @@ -30,8 +30,6 @@ import {DisplayField} from 'core-components/wp-display/wp-display-field/wp-displ export class CurrencyDisplayField extends DisplayField { - isManualRenderer = true; - public isEmpty(): boolean { return !this.value || !parseFloat(this.value.split(" ")[0]);