add missing api fields

This commit is contained in:
Jake McDermott
2018-11-10 22:44:09 -05:00
parent 2bd25b1fba
commit 38fbcf8ee6
3 changed files with 27 additions and 43 deletions

View File

@@ -4418,6 +4418,7 @@ class JobLaunchSerializer(BaseSerializer):
class WorkflowJobLaunchSerializer(BaseSerializer): class WorkflowJobLaunchSerializer(BaseSerializer):
can_start_without_user_input = serializers.BooleanField(read_only=True) can_start_without_user_input = serializers.BooleanField(read_only=True)
defaults = serializers.SerializerMethodField()
variables_needed_to_start = serializers.ReadOnlyField() variables_needed_to_start = serializers.ReadOnlyField()
survey_enabled = serializers.SerializerMethodField() survey_enabled = serializers.SerializerMethodField()
extra_vars = VerbatimField(required=False, write_only=True) extra_vars = VerbatimField(required=False, write_only=True)
@@ -4429,16 +4430,27 @@ class WorkflowJobLaunchSerializer(BaseSerializer):
class Meta: class Meta:
model = WorkflowJobTemplate model = WorkflowJobTemplate
fields = ('can_start_without_user_input', 'extra_vars', 'inventory', fields = ('ask_inventory_on_launch', 'can_start_without_user_input', 'defaults', 'extra_vars',
'survey_enabled', 'variables_needed_to_start', 'inventory', 'survey_enabled', 'variables_needed_to_start',
'node_templates_missing', 'node_prompts_rejected', 'node_templates_missing', 'node_prompts_rejected',
'workflow_job_template_data') 'workflow_job_template_data', 'survey_enabled')
read_only_fields = ('ask_inventory_on_launch',)
def get_survey_enabled(self, obj): def get_survey_enabled(self, obj):
if obj: if obj:
return obj.survey_enabled and 'spec' in obj.survey_spec return obj.survey_enabled and 'spec' in obj.survey_spec
return False return False
def get_defaults(self, obj):
defaults ={
'inventory': {
'name': getattrd(obj, 'inventory.name', None),
'id': getattrd(obj, 'inventory.pk', None)
}
}
return defaults
def get_workflow_job_template_data(self, obj): def get_workflow_job_template_data(self, obj):
return dict(name=obj.name, id=obj.id, description=obj.description) return dict(name=obj.name, id=obj.id, description=obj.description)

View File

@@ -93,9 +93,8 @@ function atLaunchTemplateCtrl (
$state.go('workflowResults', { id: data.workflow_job }, { reload: true }); $state.go('workflowResults', { id: data.workflow_job }, { reload: true });
}); });
} else { } else {
launchData.data.defaults = { launchData.data.defaults.extra_vars = wfjtData.data.extra_vars;
extra_vars: wfjtData.data.extra_vars
};
const promptData = { const promptData = {
launchConf: selectedWorkflowJobTemplate.getLaunchConf(), launchConf: selectedWorkflowJobTemplate.getLaunchConf(),
launchOptions: launchOptions.data, launchOptions: launchOptions.data,

View File

@@ -1,7 +1,6 @@
/* eslint camelcase: 0 */ /* eslint camelcase: 0 */
let Base; let Base;
let $http; let $http;
let $q;
function optionsLaunch (id) { function optionsLaunch (id) {
const req = { const req = {
@@ -13,19 +12,16 @@ function optionsLaunch (id) {
} }
function getLaunch (id) { function getLaunch (id) {
const urls = [ const req = {
`${this.path}${id}/`, method: 'GET',
`${this.path}${id}/launch/`, url: `${this.path}${id}/launch/`
]; };
const promises = urls.map(url => $http({ method: 'GET', url })); return $http(req)
.then(res => {
this.model.launch.GET = res.data;
return $q.all(promises) return res;
.then(([res, launchRes]) => {
this.model.GET = res.data;
this.model.launch.GET = launchRes.data;
return launchRes;
}); });
} }
@@ -52,28 +48,7 @@ function getSurveyQuestions (id) {
} }
function getLaunchConf () { function getLaunchConf () {
// We may need api updates to align /:id/launch data with what is returned for job templates. return this.model.launch.GET;
// For now, we splice values from the different endpoints to get the launchData we need.
const {
ask_inventory_on_launch,
ask_variables_on_launch,
survey_enabled,
} = this.model.GET;
const {
can_start_without_user_input,
variables_needed_to_start,
} = this.model.launch.GET;
const launchConf = {
ask_inventory_on_launch,
ask_variables_on_launch,
can_start_without_user_input,
survey_enabled,
variables_needed_to_start,
};
return launchConf;
} }
function canLaunchWithoutPrompt () { function canLaunchWithoutPrompt () {
@@ -104,10 +79,9 @@ function WorkflowJobTemplateModel (method, resource, config) {
return this.create(method, resource, config); return this.create(method, resource, config);
} }
function WorkflowJobTemplateModelLoader (BaseModel, _$http_, _$q_) { function WorkflowJobTemplateModelLoader (BaseModel, _$http_) {
Base = BaseModel; Base = BaseModel;
$http = _$http_; $http = _$http_;
$q = _$q_;
return WorkflowJobTemplateModel; return WorkflowJobTemplateModel;
} }
@@ -115,7 +89,6 @@ function WorkflowJobTemplateModelLoader (BaseModel, _$http_, _$q_) {
WorkflowJobTemplateModelLoader.$inject = [ WorkflowJobTemplateModelLoader.$inject = [
'BaseModel', 'BaseModel',
'$http', '$http',
'$q',
]; ];
export default WorkflowJobTemplateModelLoader; export default WorkflowJobTemplateModelLoader;