Skip to content

Commit

Permalink
fix(angular): fix missed AngularJS bindings (spinnaker#9989)
Browse files Browse the repository at this point in the history
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
mattgogerly and mergify[bot] authored May 3, 2023
1 parent afdf3c4 commit f947bf9
Show file tree
Hide file tree
Showing 12 changed files with 323 additions and 300 deletions.
10 changes: 6 additions & 4 deletions packages/core/src/region/regionSelectField.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ module(CORE_REGION_REGIONSELECTFIELD_DIRECTIVE, [])
readOnly: '=',
},
controller: function () {
const vm = this;
vm.propagate = function (data) {
vm.component[vm.field] = data;
vm.onChange();
this.$onInit = () => {
const vm = this;
vm.propagate = function (data) {
vm.component[vm.field] = data;
vm.onChange();
};
};
},
});
28 changes: 15 additions & 13 deletions packages/dcos/src/job/general.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@ module(DCOS_JOB_GENERAL_COMPONENT, []).component('dcosGeneral', {
},
templateUrl: require('./general.component.html'),
controller: function () {
if (this.general === undefined || this.general == null) {
this.general = {
cpus: 0.01,
gpus: 0.0,
mem: 128,
disk: 0,
};
}
this.$onInit = () => {
if (this.general === undefined || this.general == null) {
this.general = {
cpus: 0.01,
gpus: 0.0,
mem: 128,
disk: 0,
};
}

this.idPattern = {
test: function (id) {
const pattern = /^([a-z0-9]*(\${.+})*)*$/;
return pattern.test(id);
},
this.idPattern = {
test: function (id) {
const pattern = /^([a-z0-9]*(\${.+})*)*$/;
return pattern.test(id);
},
};
};
},
});
8 changes: 5 additions & 3 deletions packages/dcos/src/job/labels.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ module(DCOS_JOB_LABELS_COMPONENT, []).component('dcosLabels', {
},
templateUrl: require('./labels.component.html'),
controller: function () {
if (this.labels === undefined || this.labels == null) {
this.labels = {};
}
this.$onInit = () => {
if (this.labels === undefined || this.labels == null) {
this.labels = {};
}
};
},
});
8 changes: 5 additions & 3 deletions packages/dcos/src/job/schedule.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ module(DCOS_JOB_SCHEDULE_COMPONENT, []).component('dcosSchedule', {
},
templateUrl: require('./schedule.component.html'),
controller: function () {
if (this.schedule === undefined || this.schedule == null) {
this.schedule = {};
}
this.$onInit = () => {
if (this.schedule === undefined || this.schedule == null) {
this.schedule = {};
}
};
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,91 +16,93 @@ module(GOOGLE_AUTOSCALINGPOLICY_COMPONENTS_METRICSETTINGS_METRICSETTINGS_COMPONE
},
templateUrl: require('./metricSettings.component.html'),
controller: function () {
const multipleAllowedFor = {
cpuUtilization: false,
loadBalancingUtilization: false,
customMetricUtilizations: true,
};

const metricTypes = Object.keys(multipleAllowedFor);

this.targetTypesToDisplayMap = {
GAUGE: 'Gauge',
DELTA_PER_SECOND: 'Delta / second',
DELTA_PER_MINUTE: 'Delta / minute',
};

this.metricScopeTypesToDisplayMap = {
TIME_SERIES_PER_INSTANCE: 'Time series per instance',
SINGLE_TIME_SERIES_PER_GROUP: 'Single time series per group',
};

this.scalingpolicyTypesToDisplayMap = {
UTILIZATION_TARGET: 'Utilization target',
SINGLE_INSTANCE_ASSIGNMENT: 'singleInstanceAssignment',
};

this.addMetric = (metricType) => {
if (multipleAllowedFor[metricType]) {
this.policy[metricType] = this.policy[metricType] || [];
this.policy[metricType].push({});
} else if (emptyOrUndefined(this.policy[metricType])) {
this.policy[metricType] = { utilizationTarget: null };
this.$onInit = () => {
const multipleAllowedFor = {
cpuUtilization: false,
loadBalancingUtilization: false,
customMetricUtilizations: true,
};

const metricTypes = Object.keys(multipleAllowedFor);

this.targetTypesToDisplayMap = {
GAUGE: 'Gauge',
DELTA_PER_SECOND: 'Delta / second',
DELTA_PER_MINUTE: 'Delta / minute',
};

this.metricScopeTypesToDisplayMap = {
TIME_SERIES_PER_INSTANCE: 'Time series per instance',
SINGLE_TIME_SERIES_PER_GROUP: 'Single time series per group',
};

this.scalingpolicyTypesToDisplayMap = {
UTILIZATION_TARGET: 'Utilization target',
SINGLE_INSTANCE_ASSIGNMENT: 'singleInstanceAssignment',
};

this.addMetric = (metricType) => {
if (multipleAllowedFor[metricType]) {
this.policy[metricType] = this.policy[metricType] || [];
this.policy[metricType].push({});
} else if (emptyOrUndefined(this.policy[metricType])) {
this.policy[metricType] = { utilizationTarget: null };
}
};

this.deleteMetric = (metricType, index) => {
if (multipleAllowedFor[metricType]) {
this.policy[metricType].splice(index, 1);
} else {
// sending an empty object to the API deletes the policy.
this.policy[metricType] = {};
}
};

this.showMetric = (metricType) => {
const metric = this.policy[metricType];
// should not show policy form if the policy is undefined or an empty object.
return !emptyOrUndefined(metric);
};

this.isSingleTimeSeriesPerGroup = (scopeType, index) => {
if (this.policy.customMetricUtilizations[index].metricExportScope === scopeType) return true;
};

this.isScalingPolicySingleInstanceAssignment = (policyType, index) => {
if (this.policy.customMetricUtilizations[index].scalingpolicy === policyType) return true;
};

this.showNoMetricsWarning = () => {
return _.every(
metricTypes.map((type) => {
return _.some([
multipleAllowedFor[type] && !_.get(this.policy, [type, 'length']),
emptyOrUndefined(this.policy[type]),
]);
}),
);
};

this.setUtilizationTargetFromDisplay = (metricType, value) => {
this.policy[metricType].utilizationTarget = value / 100;
};

this.initializeTargetDisplay = (metricType) => {
this[`${metricType}TargetDisplay`] = safeDecimalToPercent(this.policy[metricType].utilizationTarget);
};

function safeDecimalToPercent(value) {
if (value === 0) {
return 0;
}
return value ? Math.round(value * 100) : undefined;
}
};

this.deleteMetric = (metricType, index) => {
if (multipleAllowedFor[metricType]) {
this.policy[metricType].splice(index, 1);
} else {
// sending an empty object to the API deletes the policy.
this.policy[metricType] = {};
function emptyOrUndefined(value) {
return _.isEqual(value, {}) || _.isUndefined(value);
}
};

this.showMetric = (metricType) => {
const metric = this.policy[metricType];
// should not show policy form if the policy is undefined or an empty object.
return !emptyOrUndefined(metric);
};

this.isSingleTimeSeriesPerGroup = (scopeType, index) => {
if (this.policy.customMetricUtilizations[index].metricExportScope === scopeType) return true;
};

this.isScalingPolicySingleInstanceAssignment = (policyType, index) => {
if (this.policy.customMetricUtilizations[index].scalingpolicy === policyType) return true;
};

this.showNoMetricsWarning = () => {
return _.every(
metricTypes.map((type) => {
return _.some([
multipleAllowedFor[type] && !_.get(this.policy, [type, 'length']),
emptyOrUndefined(this.policy[type]),
]);
}),
);
};

this.setUtilizationTargetFromDisplay = (metricType, value) => {
this.policy[metricType].utilizationTarget = value / 100;
};

this.initializeTargetDisplay = (metricType) => {
this[`${metricType}TargetDisplay`] = safeDecimalToPercent(this.policy[metricType].utilizationTarget);
};

function safeDecimalToPercent(value) {
if (value === 0) {
return 0;
}
return value ? Math.round(value * 100) : undefined;
}

function emptyOrUndefined(value) {
return _.isEqual(value, {}) || _.isUndefined(value);
}
},
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,46 @@ module(GOOGLE_AUTOSCALINGPOLICY_COMPONENTS_SCALINGSCHEDULES_SCALINGSCHEDULES_COM
},
templateUrl: require('./scalingSchedules.component.html'),
controller: function () {
const multipleAllowedFor = {
scalingSchedules: true,
};

this.timezones = timezones;

this.addSchedule = (scheduleType) => {
if (multipleAllowedFor[scheduleType]) {
this.policy[scheduleType] = this.policy[scheduleType] || [];
this.policy[scheduleType].push({});
} else if (emptyOrUndefined(this.policy[scheduleType])) {
this.policy[scheduleType] = {};
}
};

this.deleteSchedule = (scheduleType, index) => {
if (multipleAllowedFor[scheduleType]) {
this.policy[scheduleType].splice(index, 1);
} else {
// sending an empty object to the API deletes the policy.
this.policy[scheduleType] = {};
this.$onInit = () => {
const multipleAllowedFor = {
scalingSchedules: true,
};

this.timezones = timezones;

this.addSchedule = (scheduleType) => {
if (multipleAllowedFor[scheduleType]) {
this.policy[scheduleType] = this.policy[scheduleType] || [];
this.policy[scheduleType].push({});
} else if (emptyOrUndefined(this.policy[scheduleType])) {
this.policy[scheduleType] = {};
}
};

this.deleteSchedule = (scheduleType, index) => {
if (multipleAllowedFor[scheduleType]) {
this.policy[scheduleType].splice(index, 1);
} else {
// sending an empty object to the API deletes the policy.
this.policy[scheduleType] = {};
}
};

this.selectTimezone = (timezone, index) => {
const { scalingSchedules } = this.policy;
const schedule = scalingSchedules[index];
scalingSchedules[index] = { ...schedule, timezone };

this.updatePolicy({
...this.policy,
scalingSchedules: [...scalingSchedules],
});
};

function emptyOrUndefined(value) {
return _.isEqual(value, {}) || _.isUndefined(value);
}
};

this.selectTimezone = (timezone, index) => {
const { scalingSchedules } = this.policy;
const schedule = scalingSchedules[index];
scalingSchedules[index] = { ...schedule, timezone };

this.updatePolicy({
...this.policy,
scalingSchedules: [...scalingSchedules],
});
};

function emptyOrUndefined(value) {
return _.isEqual(value, {}) || _.isUndefined(value);
}
},
},
);
Loading

0 comments on commit f947bf9

Please sign in to comment.