<?xml version="1.0" encoding="utf-8" ?>
<odoo>

    <!-- Tree View -->
    <record id="cx_tower_git_project_view_tree" model="ir.ui.view">
        <field name="name">cx.tower.git.project.tree</field>
        <field name="model">cx.tower.git.project</field>
        <field name="arch" type="xml">
            <tree>
                <field name="name" />
                <field name="server_ids" widget="many2many_tags" />
                <field name="active" widget="boolean_toggle" />
            </tree>
        </field>
    </record>

    <!-- Form View -->
    <record id="cx_tower_git_project_view_form" model="ir.ui.view">
        <field name="name">cx.tower.git.project.form</field>
        <field name="model">cx.tower.git.project</field>
        <field name="arch" type="xml">
            <form>
                <sheet>
                    <widget
                        name="web_ribbon"
                        title="Archived"
                        bg_color="bg-danger"
                        attrs="{'invisible': [('active', '=', True)]}"
                    />
                    <div class="oe_title">
                        <h1>
                            <field name="name" placeholder="Name" />
                        </h1>
                        <h3>
                            <field
                                name="reference"
                                placeholder="Reference. Can contain English letters, digits and '_'. Leave blank to autogenerate"
                            />
                        </h3>
                    </div>
                    <group>
                        <group string="General">
                            <field name="active" invisible="1" />
                            <field
                                name="server_ids"
                                widget="many2many_tags"
                                attrs="{'invisible': [('server_ids', '=', [])]}"
                            />
                            <field
                                name="file_template_ids"
                                widget="many2many_tags"
                                attrs="{'invisible': [('file_template_ids', '=', [])]}"
                            />
                        </group>
                        <group string="Git Aggregator">
                            <field
                                name="git_aggregator_root_dir"
                                string="Root Directory"
                                placeholder="Git aggregator root directory where sources will be cloned. Leave blank to use '.'"
                            />
                        </group>
                        <field name="note" placeholder="Put your notes here..." />
                    </group>
                    <notebook>
                        <page name="sources" string="Sources">
                            <field name="source_ids">
                                <tree
                                    decoration-muted="not enabled"
                                    decoration-info="remote_count_private == remote_count and remote_count &gt; 0"
                                    decoration-warning="remote_count_private != remote_count and remote_count &gt; 0 and remote_count_private &gt; 0"
                                >
                                    <field name="sequence" widget="handle" />
                                    <field
                                        name="name"
                                        placeholder="..to be autogenerated"
                                    />
                                    <field name="remote_count" optional="show" />
                                    <field
                                        name="remote_count_private"
                                        optional="hide"
                                    />
                                    <field name="enabled" widget="boolean_toggle" />
                                    <field name="reference" optional="hide" />
                                    <field name="create_uid" optional="hide" />
                                </tree>
                            </field>
                            <field name="has_private_remotes" invisible="1" />
                            <field name="has_partially_private_remotes" invisible="1" />
                            <div
                                class="text-info"
                                attrs="{'invisible': [('has_private_remotes', '=', False)]}"
                            >
                                <p>
                                    * Sources where all remotes are private
                                </p>
                            </div>
                            <div
                                class="text-warning"
                                attrs="{'invisible': [('has_partially_private_remotes', '=', False)]}"
                            >
                                <p>
                                    * Sources where some remotes are private
                                </p>
                            </div>
                        </page>
                        <page name="files" string="Files">
                        <field name="git_project_rel_ids">
                            <tree editable="bottom">
                                <field
                                        name="server_id"
                                        options="{'no_create': True, 'no_create_edit': True}"
                                    />
                                <field
                                        name="file_id"
                                        options="{'no_create': True, 'no_create_edit': True}"
                                    />
                                <field name="project_format" />
                                <field name="auto_sync" />
                                <button
                                        type="object"
                                        name="action_open_server"
                                        string="Open Server"
                                        title="Open Server"
                                        class="btn-secondary"
                                    />
                            </tree>
                            <form>
                                <group>
                                    <field name="server_id" />
                                    <field name="file_id" />
                                    <field name="project_format" />
                                    <field name="auto_sync" />
                                </group>
                            </form>
                        </field>
                        </page>
                        <page name="file_templates" string="File Templates">
                        <field name="git_project_file_template_rel_ids">
                            <tree editable="bottom">
                                <field
                                        name="file_template_id"
                                        options="{'no_create': True, 'no_create_edit': True}"
                                    />
                                <field name="project_format" />
                                <button
                                        type="object"
                                        string="Open file template"
                                        name="action_open_file_template"
                                        title="Open File Template"
                                        class="btn-secondary"
                                    />
                            </tree>
                            <form>
                                <group>
                                    <field name="file_template_id" />
                                    <field name="project_format" />
                                </group>
                            </form>
                        </field>
                        </page>
                        <page
                            name="repos"
                            string="Repos"
                            groups="base.group_no_one"
                            attrs="{'invisible': [('repo_ids', '=', [])]}"
                        >
                            <field name="repo_ids" />
                        </page>
                        <page
                            name="access"
                            string="Access"
                            groups="cetmix_tower_server.group_manager"
                        >
                            <group name="access">
                                <field
                                    name="user_ids"
                                    widget="many2many_tags"
                                    placeholder="users who can view this record"
                                    options="{'no_create': True}"
                                />
                                <field
                                    name="manager_ids"
                                    widget="many2many_tags"
                                    placeholder="managers who can modify this record"
                                    options="{'no_create': True}"
                                />
                            </group>
                            <div
                                class="alert alert-warning"
                                role="alert"
                                style="margin-bottom:0px;"
                            >
                                <ul>
                                    <li>
                                        <b
                                        >Users.</b> All users who have "Manager" group and are either set in "Users" or in "Managers" in <b
                                        ><u>all</u></b> related servers.
                                    </li>
                                    <li>
                                        <b
                                        >Managers.</b> All users who have "Manager" group and are set as "Managers" in <b
                                        ><u>all</u></b> related servers.
                                        This is done to avoid unpredictable consequences when some of the servers are not updated due to access restrictions when a project is updated.
                                    </li>
                                </ul>
                                You can edit these fields at your own risk. However keep in mind that they will be automatically updated each time related servers are added, removed or updated.
                            </div>
                        </page>
                        <page name="yaml" string="YAML">
                        <div groups="!cetmix_tower_yaml.group_export">
                            <h3
                                >You must be a member of the "YAML/Export" group to export data as YAML.</h3>
                        </div>
                        <button
                                type="object"
                                groups="cetmix_tower_yaml.group_export"
                                class="oe_highlight"
                                name="action_open_yaml_export_wizard"
                                string="Export YAML"
                            />
                    </page>
                    </notebook>
                </sheet>
            </form>
        </field>
    </record>

    <!-- Action -->
    <record id="cx_tower_git_project_action" model="ir.actions.act_window">
        <field name="name">Git Projects</field>
        <field name="res_model">cx.tower.git.project</field>
        <field name="view_mode">tree,form</field>
    </record>


</odoo>
