in ui-modules/app-inspector/app/views/main/inspect/effectors/effectors.controller.js [23:94]
function EffectorsController($scope, $stateParams, $location, entityApi) {
$scope.$emit(HIDE_INTERSTITIAL_SPINNER_EVENT);
$scope.filterResult = [];
$scope.filterValue = $stateParams.search || '';
const {
applicationId,
entityId
} = $stateParams;
let vm = this;
vm.error = {};
vm.applicationId = applicationId;
vm.entityId = entityId;
vm.effectorToOpen = $location.search().effector;
vm.effectorTasks = {};
function updateFilters() {
if (vm.effectors) {
$scope.filterResult = vm.effectors.filter(effector => effector.name.includes($scope.filterValue)).map(effector => effector.name)
}
}
entityApi.entityTags(applicationId, entityId).then((responseE)=> {
const entityTags = responseE.data;
entityApi.entityEffectors(applicationId, entityId).then((response) => {
// filter based on ui-effector-hints single-key tag, then filter response, excluding if exclude-regex matches and include-regex does not
const effectorHint = (entityTags || []).map(t => t['ui-effector-hints']).find(t => t);
vm.effectors = response.data.map(function (effector) {
effector.parameters.map(function (parameter) {
// populate this for invocation
parameter.value = parameter.defaultValue;
if (parameter.value!=null && typeof parameter.value === 'object') {
parameter.value = jsyaml.dump(parameter.value).trim();
}
return parameter;
});
return effector;
}).filter(effector=> {
if (!effectorHint) return true;
if (effectorHint['exclude-regex'] && new RegExp(effectorHint['exclude-regex']).test(effector.name) &&
(!effectorHint['include-regex'] || !(new RegExp(effectorHint['include-regex']).test(effector.name)))) return false;
return true;
});
vm.error = {};
updateFilters();
});
}).catch((error) => {
vm.error.effectors = 'Cannot load effectors for entity with ID: ' + entityId;
console.warn(vm.error.effectors, error);
});
entityApi.entityActivities(applicationId, entityId).then((response) => {
const newTasks = {};
response.data.forEach(task => {
if ((task.tags || []).find(t => t == "EFFECTOR")) {
const name = (task.tags.find(t => t && t.effectorName) || {}).effectorName;
if (name) {
const counts = newTasks[name] = newTasks[name] || { active: 0, failed: 0, cancelled: 0, succeeded: 0 };
if (!task.endTimeUtc) counts.active++;
else if (task.isCancelled) counts.cancelled++;
else if (task.isError) counts.failed++;
else counts.succeeded++;
}
}
});
vm.effectorTasks = newTasks;
});
$scope.$watch('filterValue', () => {
updateFilters();
});
}