mirror of
https://github.com/SARL-PACIFIC-ERP/odoo-sh-test.git
synced 2025-06-25 01:32:20 +00:00
ch2.11 add and remove
This commit is contained in:
parent
7f28d797c9
commit
7a28c70b6e
|
@ -5,7 +5,9 @@ import { registry } from "@web/core/registry";
|
|||
import { Layout } from "@web/search/layout";
|
||||
import { useService } from "@web/core/utils/hooks"
|
||||
import { DashboardItem } from "./dashboard_item/dashboard_item";
|
||||
import { items } from "./dashboard_items";
|
||||
import { Dialog } from "@web/core/dialog/dialog";
|
||||
import { CheckBox } from "@web/core/checkbox/checkbox";
|
||||
import { browser } from "@web/core/browser/browser";
|
||||
|
||||
class AwesomeDashboard extends Component {
|
||||
static template = "awesome_dashboard.AwesomeDashboard";
|
||||
|
@ -21,6 +23,12 @@ class AwesomeDashboard extends Component {
|
|||
this.stats = useState(useService('awesome_dashboard.statistics'));
|
||||
|
||||
this.items = registry.category("awesome_dashboard").getAll();
|
||||
|
||||
this.dialog = useService("dialog");
|
||||
|
||||
this.state = useState({
|
||||
disabledItems: browser.localStorage.getItem("disabledDashboardItems")?.split(",") || []
|
||||
});
|
||||
}
|
||||
|
||||
openCustomers() {
|
||||
|
@ -35,6 +43,47 @@ class AwesomeDashboard extends Component {
|
|||
views: [[false, 'tree'],[false, 'form']],
|
||||
});
|
||||
}
|
||||
|
||||
openConfiguration() {
|
||||
this.dialog.add(ConfigurationDialog, {
|
||||
items: this.items,
|
||||
disabledItems: this.state.disabledItems,
|
||||
onUpdateConfiguration: this.updateConfiguration.bind(this),
|
||||
})
|
||||
}
|
||||
|
||||
updateConfiguration(newDisabledItems) {
|
||||
this.state.disabledItems = newDisabledItems;
|
||||
}
|
||||
}
|
||||
|
||||
class ConfigurationDialog extends Component {
|
||||
static template = "awesome_dashboard.ConfigurationDialog";
|
||||
static components = { Dialog, CheckBox };
|
||||
static props = ["close", "items", "disabledItems", "onUpdateConfiguration"];
|
||||
setup() {
|
||||
this.items = useState(this.props.items.map((item) => {
|
||||
return {
|
||||
...item,
|
||||
enabled: !this.props.disabledItems.includes(item.id),
|
||||
}
|
||||
}));
|
||||
}
|
||||
done() {
|
||||
this.props.close();
|
||||
}
|
||||
onChange(checked, changedItem) {
|
||||
changedItem.enabled = checked;
|
||||
const newDisabledItems = Object.values(this.items).filter(
|
||||
(item) => !item.enabled
|
||||
).map((item) => item.id)
|
||||
browser.localStorage.setItem(
|
||||
"disabledDashboardItems",
|
||||
newDisabledItems,
|
||||
);
|
||||
this.props.onUpdateConfiguration(newDisabledItems);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
registry.category("lazy_components").add("AwesomeDashboard", AwesomeDashboard);
|
|
@ -7,9 +7,14 @@
|
|||
<button class="btn btn-primary" t-on-click="openCustomers">Customers</button>
|
||||
<button class="btn btn-primary" t-on-click="openLeads">Leads</button>
|
||||
</t>
|
||||
<t t-set-slot="control-panel-additional-actions">
|
||||
<button t-on-click="openConfiguration" class="btn p-0 ms-1 border-0">
|
||||
<i class="fa fa-cog"></i>
|
||||
</button>
|
||||
</t>
|
||||
<div class="d-flex flex-wrap" t-if="stats.isReady">
|
||||
<t t-foreach="items" t-as="item" t-key="item.id">
|
||||
<DashboardItem size="item.size || 1">
|
||||
<DashboardItem t-if="!state.disabledItems.includes(item.id)" size="item.size || 1">
|
||||
<t t-set="itemProp" t-value="item.props ? item.props(stats) : {'data': stats}"/>
|
||||
<t t-component="item.Component" t-props="itemProp" />
|
||||
</DashboardItem>
|
||||
|
@ -18,4 +23,20 @@
|
|||
</Layout>
|
||||
</t>
|
||||
|
||||
<t t-name="awesome_dashboard.ConfigurationDialog">
|
||||
<Dialog title="'Dashboard items configuration'">
|
||||
Which cards do you whish to see ?
|
||||
<t t-foreach="items" t-as="item" t-key="item.id">
|
||||
<CheckBox value="item.enabled" onChange="(ev) => this.onChange(ev, item)">
|
||||
<t t-esc="item.description"/>
|
||||
</CheckBox>
|
||||
</t>
|
||||
<t t-set-slot="footer">
|
||||
<button class="btn btn-primary" t-on-click="done">
|
||||
Done
|
||||
</button>
|
||||
</t>
|
||||
</Dialog>
|
||||
</t>
|
||||
|
||||
</templates>
|
||||
|
|
Loading…
Reference in a new issue