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

Allow overriding a few default messages #89

Merged
merged 3 commits into from
Sep 9, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ The `initProgressBar` function takes an optional object of options. The followin
| onDataError | function to call on a response that's not JSON or has invalid schema due to a programming error | onError |
| onResult | function to call when returned non empty result | CeleryProgressBar.onResultDefault |
| barColors | dictionary containing color values for various progress bar states. Colors that are not specified will defer to defaults | barColorsDefault |
| defaultMessages | dictionary containing default messages that can be overridden | see below |

The `barColors` option allows you to customize the color of each progress bar state by passing a dictionary of key-value pairs of `state: #hexcode`. The defaults are shown below.

Expand All @@ -178,6 +179,13 @@ The `barColors` option allows you to customize the color of each progress bar st
| progress | #68a9ef | ![#68a9ef](https://placehold.it/15/68a9ef/000000?text=+) |
| ignored | #7a7a7a | ![#7a7a7a](https://placehold.it/15/7a7a7a/000000?text=+) |

The `defaultMessages` option allows you to override some default messages in the UI. At the moment these are:

| Message Id | When Shown | Default Value |
|-------|----------|:-------------:|
| waiting | Task is waiting to start | 'Waiting for task to start...'
| error | Task has started but reports no progress | 'Task started...'
EJH2 marked this conversation as resolved.
Show resolved Hide resolved

# WebSocket Support

Additionally, this library offers WebSocket support using [Django Channels](https://channels.readthedocs.io/en/latest/)
Expand Down
10 changes: 8 additions & 2 deletions celery_progress/static/celery_progress/celery_progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ class CeleryProgressBar {
ignored: '#7a7a7a'
}
this.barColors = Object.assign({}, barColorsDefault, options.barColors);

let defaultMessages = {
waiting: 'Waiting for task to start...',
started: 'Task started...',
}
this.messages = Object.assign({}, defaultMessages, options.defaultMessages);
}

onSuccessDefault(progressBarElement, progressBarMessageElement, result) {
Expand Down Expand Up @@ -79,9 +85,9 @@ class CeleryProgressBar {
var description = progress.description || "";
if (progress.current == 0) {
if (progress.pending === true) {
progressBarMessageElement.textContent = 'Waiting for task to start...';
progressBarMessageElement.textContent = this.messages.waiting;
} else {
progressBarMessageElement.textContent = 'Task started...';
progressBarMessageElement.textContent = this.messages.started;
}
} else {
progressBarMessageElement.textContent = progress.current + ' of ' + progress.total + ' processed. ' + description;
Expand Down