function ExecuteModulePlaybook_group_limit_callback(){let previous_inventory;let previous_format;return function(parent_values={}){let inventory=parent_values['inventory'];if(inventory&&typeof inventory=='object'&&inventory.value!==undefined){inventory=inventory.value;}
let save_value=false;if(previous_inventory===undefined||previous_inventory==inventory){save_value=true;}
previous_inventory=inventory;if(inventory&&!isNaN(Number(inventory))){let format='group_autocomplete';if(previous_format&&previous_format!=format){save_value=false;}
previous_format=format;return{format:format,default:'all',additionalProperties:{list_paths:['/project/{'+path_pk_key+'}/inventory/{inventory_id}/all_groups/','/project/{'+path_pk_key+'}/inventory/{inventory_id}/all_hosts/',],value_field:'name',view_field:'name',url_params:{inventory_id:inventory},},save_value:save_value,};}else{let format='autocomplete';if(previous_format&&previous_format!=format){save_value=false;}
previous_format=format;return{format:'autocomplete',default:'all',save_value:save_value,};}}}
function ansiblePlaybookAndAnsibleModuleModelsFieldsHandler(model){let str="models[{0}].fields.beforeInit".format([model]);tabSignal.connect(str,(fields)=>{fields.inventory.format="inventory_autocomplete";let prop;let type_props=['module','playbook'];type_props.forEach(item=>{if(model.toLowerCase().indexOf(item)!==-1){prop=item;}});if(fields[prop]){fields[prop].format=prop+"_autocomplete";}
if(fields[prop]&&fields[prop].additionalProperties&&prop=='playbook'){fields[prop].additionalProperties.view_field="playbook";}
let group_props=['group','limit'];group_props.forEach(prop=>{if(fields[prop]){fields[prop].format='dynamic';fields[prop].additionalProperties={field:['inventory'],callback:ExecuteModulePlaybook_group_limit_callback(),};}});});}
var gui_project_page_additional=Vue.component('gui_project_page_additional',{mixins:[base_page_type_mixin,collapsable_card_mixin],template:"#template_project_page_additional",data(){return{base_fields:undefined,base_fields_value:{},extra_vars:undefined,extra_vars_value:{},buttons:undefined,card_collapsed_button:true,};},created(){let instance=this.data.instance;if(instance&&instance.data&&instance.data.execute_view_data){this.base_fields=new guiFields.form(this.getBaseFieldsFormOptions());this.extra_vars=new guiFields.form(this.getExtraVarsFormOptions(instance.data.execute_view_data));this.buttons=new guiFields.form(this.getButtonsForm(instance.data.execute_view_data));}},methods:{getBaseFieldsFormOptions(){return{name:'base_fields',title:"Execute parameters",form:{inventory:{name:'inventory',title:'inventory',description:"inventory, on which playbook will be executed",required:true,format:'inventory_autocomplete',additionalProperties:{view_field:'name',value_field:'id',list_paths:['/project/{'+path_pk_key+'}/inventory/'],}},user:{name:'user',title:'User',description:"connect as this user (default=None)",format:'string',},key_file:{name:'key_file',title:'Key file',description:"use this file to authenticate the connection",format:'secretfile',},},};},getExtraVarsFormOptions(data){if(!isEmptyObject(data.fields)){return{name:'extra_vars',title:"Additional execute parameters",format:'form',form:data.fields,}}
return{form:{}};},getButtonsForm(data){if(isEmptyObject(data.playbooks)){return{form:{}};}
let buttons={};for(let key in data.playbooks){let val=data.playbooks[key];buttons[key]={name:key,title:val.title,description:val.help||val.description,format:'button',onclick:()=>{this.executePlaybook(key);},}}
return{name:'buttons',title:' ',form:buttons};},getPolemarchYamlValidData(){try{let val_base_fields=this.base_fields.toInner({base_fields:this.base_fields_value});let valid_data=this.base_fields.validateValue({base_fields:val_base_fields});let val_extra_vars=this.extra_vars.toInner({extra_vars:this.extra_vars_value});let extra_vars=this.extra_vars.validateValue({extra_vars:val_extra_vars});if(!isEmptyObject(extra_vars)){valid_data['extra_vars']=extra_vars;}
return valid_data;}catch(e){app.error_handler.defineErrorAndShow(e);}},executePlaybook(playbook){let data=this.getPolemarchYamlValidData();if(!data){return;}
data.playbook=playbook;if(data.extra_vars){data.extra_vars=JSON.stringify(data.extra_vars);}
let qs=this.view.objects.clone();qs.url=(qs.url+"execute_playbook/").format(this.$route.params);qs.formQueryAndSend('post',data).then(res=>{guiPopUp.success("Playbook was successfully executed.");if(res&&res.data&&res.data.history_id){let redirect_path="/project/{"+path_pk_key+"}/history/{history_id}/";let redirect_url;try{redirect_url=redirect_path.format($.extend(true,{},this.$route.params,{history_id:res.data.history_id}),);if(redirect_url){this.$router.push({path:redirect_url.replace(/\/$/g,"")});}}catch(e){}}}).catch(error=>{debugger;});},formOnChangeHandler(prop,value){this[prop]=value;this[prop]={...this[prop]};},},});var project_pk_mixin={watch:{'hasPolemarchYamlForm':function(value){if(value&&this.card_collapsed==false&&this.card_collapsed_button==false){this.card_collapsed=true;this.card_collapsed_button=true;}},},computed:{hasPolemarchYamlForm(){let instance=this.data.instance;if(instance&&instance.data&&instance.data.execute_view_data){return true;}
return false;},content_additional(){if(this.hasPolemarchYamlForm){return'gui_project_page_additional';}},},};var project_connected_models_dict={module:'AnsibleModule',playbook:'AnsiblePlaybook',};tabSignal.connect("views[/project/{"+path_pk_key+"}/].afterInit",(obj)=>{obj.view.mixins=obj.view.mixins.concat(project_pk_mixin);});tabSignal.connect("models[OneProject].fields.beforeInit",(fields)=>{fields.execute_view_data.format='hidden';});tabSignal.connect("models[OneModule].fields.beforeInit",(fields)=>{fields['data'].format='ansible_json';});function addSignalsForAnsibleModuleAndAnsiblePlaybookModels(){Object.entries(project_connected_models_dict).map(item=>{if(['module','playbook'].includes(item[0])){return item[1];}}).forEach(ansiblePlaybookAndAnsibleModuleModelsFieldsHandler);}
addSignalsForAnsibleModuleAndAnsiblePlaybookModels();tabSignal.connect("views[/project/].filters.beforeInit",filters=>{for(let index in filters){let filter=filters[index];if(filter.name=='status'||filter.name=='status__not'){filter.type='choices';filter.enum=[''].concat(app.models['Project'].fields.status.options.enum);}}});var ProjectVariable_value_from_key={ci_template:{additionalProperties:{list_paths:["/project/{"+path_pk_key+"}/template/"],view_field:'name',value_field:'id',}},};function ProjectVariable_value_callback(parent_values={}){if(parent_values.key&&Object.keys(ProjectVariable_value_from_key).includes(parent_values.key)){return ProjectVariable_value_from_key[parent_values.key];}
return{};}
tabSignal.connect("models[ProjectVariable].fields.beforeInit",(fields)=>{if(fields['value']&&fields['value'].additionalProperties){fields['value'].additionalProperties.callback=ProjectVariable_value_callback;}});