-
Notifications
You must be signed in to change notification settings - Fork 117
Progress bar options #3687
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
Merged
FrancoisGe
merged 2 commits into
master-mysterious-egg
from
master-mysterious-egg-loco-1
Dec 18, 2024
Merged
Progress bar options #3687
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
addons/html_builder/static/src/builder/components/WeCheckbox.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Component } from "@odoo/owl"; | ||
import { CheckBox } from "@web/core/checkbox/checkbox"; | ||
import { | ||
clickableWeWidgetProps, | ||
useClickableWeWidget, | ||
WeComponent, | ||
useDependecyDefinition, | ||
} from "../builder_helpers"; | ||
|
||
export class WeCheckbox extends Component { | ||
static template = "html_builder.WeCheckbox"; | ||
static components = { WeComponent, CheckBox }; | ||
static props = { | ||
...clickableWeWidgetProps, | ||
id: { type: String, optional: true }, | ||
}; | ||
|
||
setup() { | ||
const { state, operation, isActive } = useClickableWeWidget(); | ||
if (this.props.id) { | ||
useDependecyDefinition({ id: this.props.id, isActive }); | ||
} | ||
this.state = state; | ||
this.onChange = operation.commit; | ||
} | ||
|
||
getClassName() { | ||
return "o_field_boolean o_boolean_toggle form-switch" + (this.props.extraClassName || ""); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
addons/html_builder/static/src/builder/components/WeCheckbox.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<templates xml:space="preserve"> | ||
|
||
<t t-name="html_builder.WeCheckbox"> | ||
<WeComponent dependencies="props.dependencies"> | ||
<CheckBox className="getClassName()" onChange="onChange" value="state.isActive"/> | ||
</WeComponent> | ||
</t> | ||
|
||
</templates> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
addons/html_builder/static/src/builder/options/progress_bar_option.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { registry } from "@web/core/registry"; | ||
import { Plugin } from "@html_editor/plugin"; | ||
import { clamp } from "@web/core/utils/numbers"; | ||
class ProgressBarOptionPlugin extends Plugin { | ||
static id = "ProgressBarOption"; | ||
selector = ".s_progress_bar"; | ||
resources = { | ||
builder_options: { | ||
template: "html_builder.ProgressBarOption", | ||
selector: this.selector, | ||
}, | ||
builder_actions: this.getActions(), | ||
clean_for_save_handlers: this.cleanForSave.bind(this), | ||
}; | ||
|
||
cleanForSave({ root }) { | ||
const editingEls = root.querySelectorAll(this.selector); | ||
for (const editingEl of editingEls) { | ||
const progressBar = editingEl.querySelector(".progress-bar"); | ||
const progressLabel = editingEl.querySelector(".s_progress_bar_text"); | ||
|
||
if (!progressBar.classList.contains("progress-bar-striped")) { | ||
progressBar.classList.remove("progress-bar-animated"); | ||
} | ||
|
||
if (progressLabel && progressLabel.classList.contains("d-none")) { | ||
progressLabel.remove(); | ||
} | ||
} | ||
} | ||
getActions() { | ||
return { | ||
display: { | ||
apply: ({ editingElement, param }) => { | ||
// retro-compatibility | ||
if (editingElement.classList.contains("progress")) { | ||
editingElement.classList.remove("progress"); | ||
const progressBarEl = editingElement.querySelector(".progress-bar"); | ||
if (progressBarEl) { | ||
const wrapperEl = document.createElement("div"); | ||
wrapperEl.classList.add("progress"); | ||
progressBarEl.parentNode.insertBefore(wrapperEl, progressBarEl); | ||
wrapperEl.appendChild(progressBarEl); | ||
editingElement | ||
.querySelector(".progress-bar span") | ||
.classList.add("s_progress_bar_text"); | ||
} | ||
} | ||
|
||
const progress = editingElement.querySelector(".progress"); | ||
const progressValue = progress.getAttribute("aria-valuenow"); | ||
let progressLabel = editingElement.querySelector(".s_progress_bar_text"); | ||
|
||
if (!progressLabel && param !== "none") { | ||
progressLabel = document.createElement("span"); | ||
progressLabel.classList.add("s_progress_bar_text", "small"); | ||
progressLabel.textContent = progressValue + "%"; | ||
} | ||
|
||
if (param === "inline") { | ||
editingElement.querySelector(".progress-bar").appendChild(progressLabel); | ||
} else if (["below", "after"].includes(param)) { | ||
progress.insertAdjacentElement("afterend", progressLabel); | ||
} | ||
|
||
// Temporary hide the label. It's effectively removed in cleanForSave | ||
// if the option is confirmed | ||
progressLabel.classList.toggle("d-none", param === "none"); | ||
}, | ||
}, | ||
progressBarValue: { | ||
apply: ({ editingElement, value }) => { | ||
value = clamp(value, 0, 100); | ||
const progressBarEl = editingElement.querySelector(".progress-bar"); | ||
const progressBarTextEl = editingElement.querySelector(".s_progress_bar_text"); | ||
const progressMainEl = editingElement.querySelector(".progress"); | ||
// Target precisely the XX% not only XX to not replace wrong element | ||
// eg 'Since 1978 we have completed 45%' <- don't replace 1978 | ||
progressBarTextEl.innerText = progressBarTextEl.innerText.replace( | ||
/[0-9]+%/, | ||
value + "%" | ||
); | ||
progressMainEl.setAttribute("aria-valuenow", value); | ||
progressBarEl.style.width = value + "%"; | ||
}, | ||
getValue: ({ editingElement }) => | ||
editingElement.querySelector(".progress").getAttribute("aria-valuenow"), | ||
}, | ||
}; | ||
} | ||
} | ||
registry.category("website-plugins").add(ProgressBarOptionPlugin.id, ProgressBarOptionPlugin); |
27 changes: 27 additions & 0 deletions
27
addons/html_builder/static/src/builder/options/progress_bar_option.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<templates xml:space="preserve"> | ||
|
||
<t t-name="html_builder.ProgressBarOption"> | ||
<WeRow label.translate="Value"> | ||
<WeNumberInput action="'progressBarValue'" unit="'%'"/> | ||
</WeRow> | ||
<WeRow label.translate="Label"> | ||
<WeSelect> | ||
<WeSelectItem action="'display'" actionParam="'inline'" classAction="'s_progress_bar_label_inline'">Display Inside</WeSelectItem> | ||
<WeSelectItem action="'display'" actionParam="'below'" classAction="'s_progress_bar_label_below'">Display Below</WeSelectItem> | ||
<WeSelectItem action="'display'" actionParam="'after'" classAction="'s_progress_bar_label_after'">Display After</WeSelectItem> | ||
<WeSelectItem action="'display'" actionParam="'none'" classAction="'s_progress_bar_label_hidden'">Hide</WeSelectItem> | ||
</WeSelect> | ||
</WeRow> | ||
<WeRow label.translate="Colors"> | ||
<WeColorpicker applyTo="'.progress-bar'" styleAction="'background-color'"/> | ||
</WeRow> | ||
<WeRow label.translate="Striped"> | ||
<WeCheckbox id="'striped_option'" classAction="'progress-bar-striped'" applyTo="'.progress-bar'"/> | ||
</WeRow> | ||
<WeRow label.translate="Animated" extraClassName="'o_we_sublevel'"> | ||
<WeCheckbox classAction="'progress-bar-animated'" dependencies="'striped_option'" applyTo="'.progress-bar'"/> | ||
</WeRow> | ||
</t> | ||
|
||
</templates> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To discuss: add
isActive
or not?