mirror of
https://github.com/odoo/runbot.git
synced 2025-03-15 23:45:44 +07:00
[IMP] runbot: add javascript support for JsonDictFields
The main motivation is to be able to see existing config_data on params and edit configuration on triggers. A simple version would be to use the `FieldChar` with a simple `JSON.stringify` formater, but having some indent on field make it easier to read and edit. The multiline need make it closet to the `FieldText` than the `FieldChar` but the reset makes the browser freeze.
This commit is contained in:
parent
623255b0d8
commit
ea3191a8d0
@ -36,6 +36,8 @@
|
||||
'templates/nginx.xml',
|
||||
'templates/build_error.xml',
|
||||
|
||||
'views/assets.xml',
|
||||
|
||||
'views/branch_views.xml',
|
||||
'views/build_error_views.xml',
|
||||
'views/build_views.xml',
|
||||
|
@ -30,7 +30,7 @@ class CustomTriggerWizard(models.TransientModel):
|
||||
trigger_id = fields.Many2one('runbot.trigger', domain="[('project_id', '=', project_id)]")
|
||||
config_id = fields.Many2one('runbot.build.config', string="Config id", default=lambda self: self.env.ref('runbot.runbot_build_config_custom_multi'))
|
||||
|
||||
config_data = fields.Text("Config data") # Text, hack to make it editable waiting for json widget
|
||||
config_data = JsonDictField("Config data")
|
||||
|
||||
number_build = fields.Integer('Number builds for config multi', default=10)
|
||||
|
||||
@ -65,8 +65,7 @@ class CustomTriggerWizard(models.TransientModel):
|
||||
@api.onchange('number_build', 'child_extra_params', 'child_dump_url', 'child_config_id')
|
||||
def _onchange_config_data(self):
|
||||
for wizard in self:
|
||||
config_data = self._get_config_data()
|
||||
wizard.config_data = json.dumps(config_data, indent=True)
|
||||
wizard.config_data = self._get_config_data()
|
||||
|
||||
def _get_config_data(self):
|
||||
config_data = {}
|
||||
@ -93,5 +92,5 @@ class CustomTriggerWizard(models.TransientModel):
|
||||
'bundle_id': self.bundle_id.id,
|
||||
'trigger_id': self.trigger_id.id,
|
||||
'config_id': self.config_id.id,
|
||||
'config_data': json.loads(self.config_data),
|
||||
'config_data': self.config_data,
|
||||
})
|
||||
|
44
runbot/static/src/js/json_field.js
Normal file
44
runbot/static/src/js/json_field.js
Normal file
@ -0,0 +1,44 @@
|
||||
odoo.define('runbot.json_field', function (require) {
|
||||
"use strict";
|
||||
|
||||
var basic_fields = require('web.basic_fields');
|
||||
var registry = require('web.field_registry');
|
||||
var field_utils = require('web.field_utils');
|
||||
var dom = require('web.dom');
|
||||
|
||||
|
||||
var FieldJson = basic_fields.FieldChar.extend({
|
||||
init: function () {
|
||||
this._super.apply(this, arguments);
|
||||
|
||||
if (this.mode === 'edit') {
|
||||
this.tagName = 'textarea';
|
||||
}
|
||||
this.autoResizeOptions = {parent: this};
|
||||
},
|
||||
|
||||
start: function () {
|
||||
if (this.mode === 'edit') {
|
||||
dom.autoresize(this.$el, this.autoResizeOptions);
|
||||
}
|
||||
return this._super();
|
||||
},
|
||||
_onKeydown: function (ev) {
|
||||
if (ev.which === $.ui.keyCode.ENTER) {
|
||||
ev.stopPropagation();
|
||||
return;
|
||||
}
|
||||
this._super.apply(this, arguments);
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
registry.add('jsonb', FieldJson)
|
||||
console.log(field_utils);
|
||||
|
||||
function stringify(obj) {
|
||||
return JSON.stringify(obj, null, '\t')
|
||||
}
|
||||
field_utils.format.jsonb = stringify;
|
||||
field_utils.parse.jsonb = JSON.parse;
|
||||
});
|
7
runbot/views/assets.xml
Normal file
7
runbot/views/assets.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<odoo>
|
||||
<template id="runbot_json_field" inherit_id="web.assets_backend" active="True">
|
||||
<xpath expr="." position="inside">
|
||||
<script type="text/javascript" src="/runbot/static/src/js/json_field.js"></script>
|
||||
</xpath>
|
||||
</template>
|
||||
</odoo>
|
@ -6,19 +6,37 @@
|
||||
<form string="Build Params">
|
||||
<sheet>
|
||||
<group>
|
||||
<field name="config_id"/>
|
||||
<field name="config_data"/>
|
||||
<field name="version_id"/>
|
||||
<field name="extra_params"/>
|
||||
<field name="commit_link_ids">
|
||||
<tree>
|
||||
<field name="commit_id"/>
|
||||
<field name="match_type"/>
|
||||
</tree>
|
||||
</field>
|
||||
<field name="trigger_id"/>
|
||||
<field name="create_batch_id"/>
|
||||
<field name="dockerfile_id"/>
|
||||
<group colspan="2">
|
||||
<field name="config_id"/>
|
||||
<field name="config_data"/>
|
||||
<field name="extra_params"/>
|
||||
<field name="dockerfile_id"/>
|
||||
<field name="dump_db"/>
|
||||
</group>
|
||||
<group colspan="2">
|
||||
<field name="trigger_id"/>
|
||||
<field name="create_batch_id"/>
|
||||
<field name="version_id"/>
|
||||
<field name="used_custom_trigger"/>
|
||||
</group>
|
||||
</group>
|
||||
<group>
|
||||
<notebook>
|
||||
<page string="Commits">
|
||||
<field name="commit_link_ids">
|
||||
<tree>
|
||||
<field name="commit_id"/>
|
||||
<field name="match_type"/>
|
||||
</tree>
|
||||
</field>
|
||||
</page>
|
||||
<page string="Builds">
|
||||
<field name="build_ids"/>
|
||||
</page>
|
||||
<page string="Reference Builds">
|
||||
<field name="builds_reference_ids"/>
|
||||
</page>
|
||||
</notebook>
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
@ -89,9 +107,7 @@
|
||||
<field name="dest"/>
|
||||
<field name="global_state"/>
|
||||
<field name="global_result"/>
|
||||
<field name="port"/>
|
||||
<field name="job"/>
|
||||
<field name="coverage_result"/>
|
||||
<field name="host"/>
|
||||
<field name="build_time"/>
|
||||
<field name="build_age"/>
|
||||
|
@ -65,6 +65,7 @@
|
||||
<field name="trigger_id" domain="[('project_id', '=', parent.project_id)]"/>
|
||||
<field name="config_id"/>
|
||||
<field name="extra_params"/>
|
||||
<field name="config_data"/>
|
||||
</tree>
|
||||
</field>
|
||||
<field string="Last batches" name="last_batchs">
|
||||
@ -79,6 +80,35 @@
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_runbot_custom_trigger_tree" model="ir.ui.view">
|
||||
<field name="model">runbot.bundle.trigger.custom</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Bundle">
|
||||
<field name="bundle_id"/>
|
||||
<field name="trigger_id"/>
|
||||
<field name="config_id"/>
|
||||
<field name="extra_params"/>
|
||||
<field name="config_data"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_runbot_custom_trigger_form" model="ir.ui.view">
|
||||
<field name="model">runbot.bundle.trigger.custom</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Bundle">
|
||||
<group>
|
||||
<field name="bundle_id"/>
|
||||
<field name="trigger_id"/>
|
||||
<field name="config_id"/>
|
||||
<field name="extra_params"/>
|
||||
<field name="config_data"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_runbot_bundle_tree" model="ir.ui.view">
|
||||
<field name="model">runbot.bundle</field>
|
||||
<field name="arch" type="xml">
|
||||
@ -121,6 +151,7 @@
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_runbot_batch_tree" model="ir.ui.view">
|
||||
<field name="model">runbot.batch</field>
|
||||
<field name="arch" type="xml">
|
||||
@ -142,7 +173,12 @@
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_bundle_custom_trigger" model="ir.actions.act_window">
|
||||
<field name="name">Custom triggers</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">runbot.bundle.trigger.custom</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
</record>
|
||||
<record id="action_bundle" model="ir.actions.act_window">
|
||||
<field name="name">Bundles</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
|
@ -10,11 +10,10 @@
|
||||
<menuitem name="Branches" id="runbot_menu_branch_tree" parent="menu_objects" sequence="40" action="open_view_branch_tree"/>
|
||||
<menuitem name="Commits" id="runbot_menu_commit_tree" parent="menu_objects" sequence="50" action="open_view_commit_tree"/>
|
||||
<menuitem name="Statistics" id="runbot_menu_stat_tree" parent="menu_objects" sequence="60" action="open_view_stat_sql_tree"/>
|
||||
|
||||
<menuitem id="runbot_menu_bundle_custom_trigger" parent="menu_objects" sequence="70" action="action_bundle_custom_trigger"/>
|
||||
|
||||
<menuitem name="Hosts" id="runbot_menu_host_tree" parent="runbot_menu_root" sequence="300" action="open_view_host_tree"/>
|
||||
|
||||
|
||||
<menuitem id="runbot_menu_trigger" parent="runbot_menu_root" sequence="500" action="runbot_triggers_action"/>
|
||||
|
||||
<menuitem name="Configs" id="runbot_menu_configs" parent="runbot_menu_root" sequence="600"/>
|
||||
|
Loading…
Reference in New Issue
Block a user