[MOV] hr_org_chart,web_hierarchy: move hierarchy view in its own module

This commit moves the generic code of hierarchy view into new module
called `web_hierarchy` to be able to use it outside the hr scope.

task-3376776
This commit is contained in:
Xavier Bol (xbo)
2023-10-16 08:17:31 +02:00
parent 55571bc1ac
commit a055b9c20e
29 changed files with 51 additions and 21 deletions
+2 -6
View File
@@ -13,8 +13,8 @@ Org Chart Widget for HR
This module extend the employee form with a organizational chart. This module extend the employee form with a organizational chart.
(N+1, N+2, direct subordinates) (N+1, N+2, direct subordinates)
""", """,
'depends': ['hr'], 'depends': ['hr', 'web_hierarchy'],
'auto_install': True, 'auto_install': ['hr'],
'data': [ 'data': [
'views/hr_department_views.xml', 'views/hr_department_views.xml',
'views/hr_views.xml', 'views/hr_views.xml',
@@ -26,13 +26,9 @@ This module extend the employee form with a organizational chart.
'hr_org_chart/static/src/scss/variables.scss', 'hr_org_chart/static/src/scss/variables.scss',
], ],
'web.assets_backend': [ 'web.assets_backend': [
'hr_org_chart/static/src/scss/hierarchy.variables.scss',
'hr_org_chart/static/src/fields/*', 'hr_org_chart/static/src/fields/*',
'hr_org_chart/static/src/views/**/*', 'hr_org_chart/static/src/views/**/*',
], ],
'web.assets_web_dark': [
('before', 'hr_org_chart/static/src/scss/hierarchy.variables.scss', 'hr_org_chart/static/src/scss/**/*.variables.dark.scss'),
],
'web.qunit_suite_tests': [ 'web.qunit_suite_tests': [
'hr_org_chart/static/tests/**/*', 'hr_org_chart/static/tests/**/*',
], ],
-3
View File
@@ -3,6 +3,3 @@
from . import hr_org_chart_mixin from . import hr_org_chart_mixin
from . import hr_employee from . import hr_employee
from . import ir_actions
from . import ir_ui_view
from . import models
@@ -2,7 +2,7 @@
import { Avatar } from "@mail/views/web/fields/avatar/avatar"; import { Avatar } from "@mail/views/web/fields/avatar/avatar";
import { HierarchyRenderer } from "../hierarchy/hierarchy_renderer"; import { HierarchyRenderer } from "@web_hierarchy/hierarchy_renderer";
export class HrEmployeeHierarchyRenderer extends HierarchyRenderer { export class HrEmployeeHierarchyRenderer extends HierarchyRenderer {
static template = "hr_org_chart.HrEmployeeHierarchyRenderer"; static template = "hr_org_chart.HrEmployeeHierarchyRenderer";
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<templates> <templates>
<t t-name="hr_org_chart.HrEmployeeHierarchyRenderer" t-inherit="hr_org_chart.HierarchyRenderer"> <t t-name="hr_org_chart.HrEmployeeHierarchyRenderer" t-inherit="web_hierarchy.HierarchyRenderer">
<xpath expr="//div[hasclass('o_hierarchy_parent_node_container')]/span" position="replace"> <xpath expr="//div[hasclass('o_hierarchy_parent_node_container')]/span" position="replace">
<Avatar <Avatar
resModel="row.parentNode.model.resModel" resModel="row.parentNode.model.resModel"
@@ -1,7 +1,7 @@
/** @odoo-module **/ /** @odoo-module **/
import { registry } from "@web/core/registry"; import { registry } from "@web/core/registry";
import { hierarchyView } from "../hierarchy/hierarchy_view"; import { hierarchyView } from "@web_hierarchy/hierarchy_view";
import { HrEmployeeHierarchyRenderer } from "./hr_employee_hierarchy_renderer"; import { HrEmployeeHierarchyRenderer } from "./hr_employee_hierarchy_renderer";
export const hrEmployeeHierarchyView = { export const hrEmployeeHierarchyView = {
+3
View File
@@ -0,0 +1,3 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import models
+29
View File
@@ -0,0 +1,29 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
{
'name': 'Web Hierarchy',
'category': 'Hidden',
'version': '1.0',
'description':
"""
Odoo Web Hierarchy view
=======================
This module adds a new view called to be able to define a view to display
an organization such as an Organization Chart for employees for instance.
""",
'depends': ['web'],
'assets': {
'web.assets_backend': [
'web_hierarchy/static/src/hierarchy.variables.scss',
'web_hierarchy/static/src/**/*',
],
'web.assets_web_dark': [
('before', 'web_hierarchy/static/src/hierarchy.variables.scss', 'web_hierarchy/static/src/**/*.variables.dark.scss'),
],
'web.qunit_suite_tests': [
'web_hierarchy/static/tests/**/*',
],
},
'license': 'LGPL-3',
}
+5
View File
@@ -0,0 +1,5 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import ir_actions
from . import ir_ui_view
from . import models
@@ -26,7 +26,7 @@ export class HierarchyCard extends Component {
static defaultProps = { static defaultProps = {
classNames: "", classNames: "",
}; };
static template = "hr_org_chart.HierarchyCard"; static template = "web_hierarchy.HierarchyCard";
static Compiler = HierarchyCompiler; static Compiler = HierarchyCompiler;
setup() { setup() {
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<templates> <templates>
<t t-name="hr_org_chart.HierarchyCard"> <t t-name="web_hierarchy.HierarchyCard">
<div class="o_hierarchy_node_container mb-4 d-flex flex-column" t-att-class="classNames" t-att-data-node-id="props.node.id"> <div class="o_hierarchy_node_container mb-4 d-flex flex-column" t-att-class="classNames" t-att-data-node-id="props.node.id">
<div class="o_hierarchy_node_button_container w-100 d-flex justify-content-end"> <div class="o_hierarchy_node_button_container w-100 d-flex justify-content-end">
<button t-if="props.node.parentResId !== false and !props.node.parentNode" <button t-if="props.node.parentResId !== false and !props.node.parentNode"
@@ -25,7 +25,7 @@ export class HierarchyController extends Component {
buttonTemplate: String, buttonTemplate: String,
archInfo: Object, archInfo: Object,
}; };
static template = "hr_org_chart.HierarchyView"; static template = "web_hierarchy.HierarchyView";
setup() { setup() {
this.rootRef = useRef("root"); this.rootRef = useRef("root");
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<templates> <templates>
<t t-name="hr_org_chart.HierarchyButtons" owl="1"> <t t-name="web_hierarchy.HierarchyButtons" owl="1">
<div class="d-flex o_grid_buttons"> <div class="d-flex o_grid_buttons">
<div class="me-2" t-if="props.archInfo.activeActions.create and (!props.archInfo.createInline or displayNoContent)"> <div class="me-2" t-if="props.archInfo.activeActions.create and (!props.archInfo.createInline or displayNoContent)">
<button class="btn btn-primary o_hierarchy_button_add" <button class="btn btn-primary o_hierarchy_button_add"
@@ -11,7 +11,7 @@
</div> </div>
</div> </div>
</t> </t>
<t t-name="hr_org_chart.HierarchyView" owl="1"> <t t-name="web_hierarchy.HierarchyView" owl="1">
<div t-attf-class="o_hierarchy_view {{ isMobile ? 'o_action_delegate_scroll' : '' }} {{ props.className }}" t-ref="root"> <div t-attf-class="o_hierarchy_view {{ isMobile ? 'o_action_delegate_scroll' : '' }} {{ props.className }}" t-ref="root">
<Layout className="(model.useSampleModel ? 'o_view_sample_data' : '') + ' d-flex'" display="props.display"> <Layout className="(model.useSampleModel ? 'o_view_sample_data' : '') + ' d-flex'" display="props.display">
<t t-set-slot="control-panel-additional-actions"> <t t-set-slot="control-panel-additional-actions">
@@ -7,7 +7,7 @@ import { useService } from "@web/core/utils/hooks";
import { scrollTo } from "@web/core/utils/scrolling"; import { scrollTo } from "@web/core/utils/scrolling";
import { HierarchyCard } from "./hierarchy_card"; import { HierarchyCard } from "./hierarchy_card";
import { useHierarchyNodeDraggable } from "../../hooks/hierarchy_node_draggable"; import { useHierarchyNodeDraggable } from "./hierarchy_node_draggable";
export class HierarchyRenderer extends Component { export class HierarchyRenderer extends Component {
static components = { static components = {
@@ -19,7 +19,7 @@ export class HierarchyRenderer extends Component {
archInfo: Object, archInfo: Object,
templates: Object, templates: Object,
}; };
static template = "hr_org_chart.HierarchyRenderer"; static template = "web_hierarchy.HierarchyRenderer";
setup() { setup() {
this.rendererRef = useRef("renderer"); this.rendererRef = useRef("renderer");
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<templates> <templates>
<t t-name="hr_org_chart.HierarchyRenderer" owl="1"> <t t-name="web_hierarchy.HierarchyRenderer" owl="1">
<div class="o_hierarchy_renderer w-100 d-flex justify-content-center" t-ref="renderer"> <div class="o_hierarchy_renderer w-100 d-flex justify-content-center" t-ref="renderer">
<div class="o_hierarchy_container d-flex flex-column w-100 w-lg-75 h-100 pt-5 px-2"> <div class="o_hierarchy_container d-flex flex-column w-100 w-lg-75 h-100 pt-5 px-2">
<t t-foreach="rows" t-as="row" t-key="row_index"> <t t-foreach="rows" t-as="row" t-key="row_index">
@@ -17,7 +17,7 @@ export const hierarchyView = {
Controller: HierarchyController, Controller: HierarchyController,
Model: HierarchyModel, Model: HierarchyModel,
Renderer: HierarchyRenderer, Renderer: HierarchyRenderer,
buttonTemplate: "hr_org_chart.HierarchyButtons", buttonTemplate: "web_hierarchy.HierarchyButtons",
searchMenuTypes: [], searchMenuTypes: [],
props: (genericProps, view) => { props: (genericProps, view) => {