Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] cetmix_tower_server: implement UI updates #185

Open
wants to merge 2 commits into
base: 14.0-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cetmix_tower_server/models/cx_tower_command_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ class CxTowerCommandLog(models.Model):
plan_log_id = fields.Many2one(comodel_name="cx.tower.plan.log", ondelete="cascade")
triggered_plan_log_id = fields.Many2one(comodel_name="cx.tower.plan.log")

# -- Related fields for plan_log_id
plan_start_date = fields.Datetime(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to show all these fields. Just show the related flight_plan_line.

<field name="plan_log_id" attrs="{'invisible': [('plan_log_id', '=', False)]}"/>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still pending.

related="plan_log_id.start_date", store=True, string="Plan Start Date"
)
plan_finish_date = fields.Datetime(
related="plan_log_id.finish_date", store=True, string="Plan Finish Date"
)
plan_status = fields.Integer(
related="plan_log_id.plan_status", store=True, string="Plan Status"
)
plan_is_running = fields.Boolean(
related="plan_log_id.is_running", store=True, string="Plan Running"
)

@api.depends("name", "command_id.name")
def _compute_name(self):
for rec in self:
Expand Down
35 changes: 34 additions & 1 deletion cetmix_tower_server/models/cx_tower_plan_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@ class CxTowerPlanLine(models.Model):
help="Actions trigger based on command result."
" If empty next command will be executed",
)
command_code = fields.Text(related="command_id.code", readonly=True)
command_code = fields.Text(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach doesn't allow to check those lines if required.
So we need to add a compute o2m field for lines and hide/show it based on the command action.

string="Code", compute="_compute_command_code", readonly=True
)
plan_line_ids = fields.One2many(
comodel_name="cx.tower.plan.line",
compute="_compute_plan_line_ids",
string="Plan Lines",
readonly=True,
)
action = fields.Selection(related="command_id.action", readonly=True)
tag_ids = fields.Many2many(related="command_id.tag_ids", readonly=True)
access_level = fields.Selection(
Expand Down Expand Up @@ -88,6 +96,31 @@ def _check_command_id(self):
visited_plans = set()
self._check_recursive_plan(line.command_id, visited_plans)

@api.depends("command_id", "action")
def _compute_command_code(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to compute anything. Just hide this field if command action is not SSH or Python.

"""
Compute the preview of the command based on its action.
"""
for line in self:
if line.action == "file_using_template":
line.command_code = line.command_id.code or "No template code available"
elif line.action == "plan":
line.command_code = False
elif line.action != "plan":
line.command_code = "No preview available"

@api.depends("command_id", "action")
def _compute_plan_line_ids(self):
"""
Compute the related plan lines if the action is "plan".
"""
for line in self:
if line.action == "plan":
flight_plan = line.command_id.flight_plan_id
line.plan_line_ids = flight_plan.line_ids if flight_plan else []
else:
line.plan_line_ids = False

def _check_recursive_plan(self, command, visited_plans):
"""
Recursively check if the command plan creates a cycle.
Expand Down
28 changes: 27 additions & 1 deletion cetmix_tower_server/views/cx_tower_command_log_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,32 @@
<field name="duration_current" />
</group>
</group>
<group>
<field
name="plan_log_id"
attrs="{'invisible': [('plan_log_id', '=', False)]}"
/>
<field
name="plan_start_date"
string="Plan Start Date"
attrs="{'invisible': [('plan_log_id', '=', False)]}"
/>
<field
name="plan_finish_date"
string="Plan Finish Date"
attrs="{'invisible': [('plan_log_id', '=', False)]}"
/>
<field
name="plan_status"
string="Plan Status"
attrs="{'invisible': [('plan_log_id', '=', False)]}"
/>
<field
name="plan_is_running"
string="Plan Running"
attrs="{'invisible': [('plan_log_id', '=', False)]}"
/>
</group>
<notebook attrs="{'invisible': [('command_action', '=', 'plan')]}">
<page name="result" string="Result">
<field
Expand All @@ -99,7 +125,7 @@
<field name="model">cx.tower.command.log</field>
<field name="arch" type="xml">
<tree
default_order="id"
default_order="start_date desc, id desc"
decoration-danger="command_status not in [0, -20]"
decoration-info="is_running == True"
decoration-muted="command_status == -20"
Expand Down
5 changes: 5 additions & 0 deletions cetmix_tower_server/views/cx_tower_command_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@
name="file_from_template"
domain="[('action', '=', 'file_using_template')]"
/>
<filter
string="Run Flight Plan"
name="filter_flight_plan"
domain="[('action', '=', 'plan')]"
/>
<separator />
<filter
string="Tagged"
Expand Down
10 changes: 9 additions & 1 deletion cetmix_tower_server/views/cx_tower_plan_line_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,15 @@
<notebook>
<page name="preview" string="Command Preview">
<group>
<field name="command_code" />
<field name="action" />
<field
name="command_code"
attrs="{'invisible': [('action', '=', 'plan')]}"
/>
<field
name="plan_line_ids"
attrs="{'invisible': [('action', '!=', 'plan')]}"
/>
</group>
</page>
<page name="actions" string="Post Run Actions">
Expand Down
1 change: 1 addition & 0 deletions cetmix_tower_server/views/cx_tower_plan_log_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<field name="model">cx.tower.plan.log</field>
<field name="arch" type="xml">
<tree
default_order="start_date desc, id desc"
decoration-danger="plan_status != 0"
decoration-info="is_running == True"
>
Expand Down
6 changes: 5 additions & 1 deletion cetmix_tower_server/views/cx_tower_server_template_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<field name="tag_ids" />
<field name="os_id" />
<field name="color" />
<field name="server_count" />
<templates>
<t t-name="kanban-box">
<div
Expand Down Expand Up @@ -56,7 +57,10 @@
<div class="oe_kanban_global_click">
<div class="col-12 pt8 o_kanban_primary_right">
<div>
<field name="reference" />
<strong>Servers:</strong>
<span class="badge badge-primary">
<t t-esc="record.server_count.value" />
</span>
</div>
<div attrs="{'invisible': [('os_id', '=', False)]}">
<strong>Operating System:</strong>
Expand Down
Loading