<?xml version="1.0" encoding="utf-8" ?>
<odoo>
    <record id="cx_tower_command_log_view_form" model="ir.ui.view">
        <field name="name">cx.tower.command.log.view.form</field>
        <field name="model">cx.tower.command.log</field>
        <field name="arch" type="xml">
            <form>
                <sheet>
                    <widget
                        name="web_ribbon"
                        title="Running"
                        bg_color="bg-info"
                        attrs="{'invisible': [('is_running', '=', False)]}"
                    />
                    <widget
                        name="web_ribbon"
                        title="Finished"
                        attrs="{'invisible': ['|', ('is_running', '=', True), '&amp;', ('is_running', '=', False), ('command_status', '!=', 0)]}"
                    />
                    <widget
                        name="web_ribbon"
                        title="Failed"
                        bg_color="bg-danger"
                        attrs="{'invisible': ['|', ('is_running', '=', True), '&amp;', ('is_running', '=', False), ('command_status', 'in', [0, -205])]}"
                    />
                    <widget
                        name="web_ribbon"
                        title="Skipped"
                        bg_color="bg-dark"
                        attrs="{'invisible': ['|', ('is_running', '=', True), '&amp;', ('is_running', '=', False), ('command_status', '!=', -205)]}"
                    />

                    <group>
                        <group>
                            <field name="is_skipped" invisible="1" />
                            <field name="create_uid" />
                            <field name="server_id" />
                            <field name="command_id" />
                            <field name="command_action" invisible="1" />
                            <field
                                name="condition"
                                attrs="{'invisible': [('condition', '=', False)]}"
                                widget="ace"
                                options="{'mode': 'python'}"
                            />
                            <field
                                name="path"
                                attrs="{'invisible': [('path', '=', False)]}"
                            />
                            <field
                                name="is_running"
                                attrs="{'invisible': [('is_running', '=', False)]}"
                            />
                            <field
                                name="use_sudo"
                                attrs="{'invisible': [('use_sudo', '=', False)]}"
                            />
                            <field
                                name="plan_log_id"
                                invisible="context.get('opened_from_plan', False)"
                                attrs="{'invisible': [('plan_log_id', '=', False)]}"
                            />
                            <field
                                name="triggered_plan_log_id"
                                attrs="{'invisible': [('triggered_plan_log_id', '=', False)]}"
                            />
                            <field
                                name="scheduled_task_id"
                                attrs="{'invisible': [('scheduled_task_id', '=', False)]}"
                            />
                        </group>
                        <group>
                            <field
                                name="label"
                                attrs="{'invisible': [('label', '=', False)]}"
                            />
                            <field name="start_date" />
                            <field name="finish_date" />
                            <field name="duration_current" />
                             <field
                                name="command_status"
                                attrs="{'invisible': [('is_running', '=', True)]}"
                            />
                        </group>
                    </group>
                    <notebook>
                        <page
                            name="result"
                            string="Result"
                            attrs="{'invisible': [('command_action', '=', 'plan')]}"
                        >
                            <field
                                name="command_result_html"
                                attrs="{'invisible': [('command_result_html', '=', False)]}"
                            />
                        </page>
                        <page
                            name="code"
                            string="Command"
                            attrs="{'invisible': [('command_action', '=', 'plan')]}"
                        >
                            <field name="code" />
                        </page>
                          <page
                            string="Triggered Commands"
                            attrs="{'invisible': [('command_action','!=','plan')]}"
                        >
                                <field name="triggered_plan_command_log_ids">
                                    <tree default_order="id asc" />
                                </field>
                        </page>
                    </notebook>
                </sheet>
            </form>
        </field>
    </record>

    <record id="cx_tower_command_log_view_tree" model="ir.ui.view">
        <field name="name">cx.tower.command.log.view.tree</field>
        <field name="model">cx.tower.command.log</field>
        <field name="arch" type="xml">
            <tree
                decoration-danger="command_status not in [0, -205]"
                decoration-info="is_running == True"
                decoration-muted="command_status == -205"
            >
                <field name="start_date" />
                <field name="finish_date" optional="hide" />
                <field name="duration_current" optional="show" />
                <field name="server_id" optional="show" />
                <field name="command_id" optional="show" />
                <field name="command_action" optional="show" />
                <field name="command_status" optional="show" />
                <field name="is_running" optional="hide" />
            </tree>
        </field>
    </record>

    <record id="cx_tower_command_log_search_view" model="ir.ui.view">
        <field name="name">cx.tower.command.log.view.search</field>
        <field name="model">cx.tower.command.log</field>
        <field name="arch" type="xml">
            <search string="Search Command Log">
                <field name="command_id" />
                <field name="server_id" />
                <field name="label" />
                <separator />
                <filter
                    string="Success"
                    name="filter_success"
                    domain="[('command_status', '=', 0)]"
                />
                <filter
                    string="Error"
                    name="filter_error"
                    domain="[('command_status', '!=', 0)]"
                />
                <filter
                    string="Running Now"
                    name="filter_is_running"
                    domain="[('is_running', '=', True)]"
                />
                <separator />
                <filter
                    string="Labeled"
                    name="filter_labeled"
                    domain="[('label', '!=', False)]"
                />
                <group expand="0" string="Group By">
                    <filter
                        string="Server"
                        name="group_server"
                        domain="[]"
                        context="{'group_by': 'server_id'}"
                    />
                    <filter
                        string="Command"
                        name="group_command"
                        domain="[]"
                        context="{'group_by': 'command_id'}"
                    />
                    <filter
                        string="Action"
                        name="group_action"
                        domain="[]"
                        context="{'group_by': 'command_action'}"
                    />
                    <filter
                        string="Start date"
                        name="group_start"
                        domain="[]"
                        context="{'group_by': 'start_date:day'}"
                    />
                    <filter
                        string="Finish date"
                        name="group_finish"
                        domain="[]"
                        context="{'group_by': 'finish_date:day'}"
                    />
                </group>
                <searchpanel>
                    <field name="command_action" string="Action" icon="fa-cog" />
                </searchpanel>
            </search>
        </field>
    </record>

    <record id="action_cx_tower_command_log" model="ir.actions.act_window">
        <field name="name">Command Log</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">cx.tower.command.log</field>
        <field name="view_mode">tree,form</field>
        <field name="context">{}</field>
    </record>

</odoo>
