Code Monkey home page Code Monkey logo

ember-toastr's Introduction

ember-toastr

A service wrapper for toastr.js with auto injection into routes, components, and controllers.

npm version Build Status Ember Observer Score

Compatibility

Usage

ember install ember-toastr

You can now access the notifications service as toast. You can inject it in routes, controllers or components using the following syntax:

import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';

export default class SomeController extends Controller {
  @service toast;

  @action
  test() {
    let title = 'Test';
    let message = 'A test happened';

    this.toast.info(message, title, {
      // options here
    });
  }
}

If using newer versions of Ember you can inject using the decorator syntax, see the Ember documentation for @ember/service#inject decorator.

You can also use toast.clear() and toast.remove() to remove all toasts. For example:

<button {{on "click" this.toast.clear}}>Clear</button>

See the toastr.js demo for other possible uses, and the toastr.js documentation for explanation of options.

API

toast Service

success(msg = '', title = '', options = {})

A method with the above default values for displaying a success toast.

info(msg = '', title = '', options = {})

A method with the above default values for displaying a info toast.

warning(msg = '', title = '', options = {})

A method with the above default values for displaying a warning toast.

error(msg = '', title = '', options = {})

A method with the above default values for displaying an error toast.

clear() or clear(toast)

A method to clear all toasts, or the individual toast.

remove() or remove(toast)

A method to remove all toasts, or the individual toast.

toasts

A property to access all toasts that are added.

Configuration

These are the default options:

ENV['ember-toastr'] = {
  toastrOptions: {
    closeButton: true,
    debug: false,
    newestOnTop: true,
    progressBar: true,
    positionClass: 'toast-top-right',
    preventDuplicates: true,
    onclick: null,
    showDuration: '300',
    hideDuration: '1000',
    timeOut: '4000',
    extendedTimeOut: '1000',
    showEasing: 'swing',
    hideEasing: 'linear',
    showMethod: 'fadeIn',
    hideMethod: 'fadeOut',
  },
};

All options in toastrOptions are direct options for toastr.js.

Testing Toasts in Acceptance Tests

Toastr messages are rendered inside a div#toast-container, but outside of div#ember-testing-container, where all of the testing action takes place. Therefore, you need to supply a second scope parameter of document to your assert.dom(...) calls.

For example: assert.dom('#toast-container', document).includesText('ERROR: Invalid username or password');

Contributing

See the Contributing guide for details.

ember-toastr's People

Contributors

coladarci avatar dependabot[bot] avatar ember-tomster avatar knownasilya avatar m-adler avatar mapeveri avatar richgt avatar samchrisinger avatar wcurtis avatar zomarg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ember-toastr's Issues

Toastr dependency defined in dependencies

Hi, first of all, thanks for this awesome addon.

I found that using this addon, I need to specify toastr dependency in my package.json. I think it would make a sense that this dependency would be specified in this addon. Than I don't need to upgrade toastr on my own in my own package.

What do you think about that?

Thanks,
Ondrej

Remove bower dependency

Hi guys

Could you work towards removing the Bower dependency and use yarn/npm instead please as ember itself is doing.

Thanks
Caltor

Change initialize arguments

Ember version: 2.1.0
ember-toastr: 1.1.1

DEPRECATION: The initialize method for Application initializer 'ember-toastr' should take only one argument - App, an instance of an Application. [deprecation id: ember-application.app-initializer-initialize-arguments]

toastr.subscribe is not working with ember-toastr

I have to provide a callback with a toast notification. I see that ember-toastr is using toastr 2.1.4 which has support for subscribe but it is not working with ember-toastr. I am getting this exception.Query.Deferred exception: toastr.subscribe is not a function TypeError: toastr.subscribe is not a function.

Override global option (the 3rd parameter)

Hi, if it is not too much trouble can you implement to allow override of global parameter when calling toastr. Looking at the code, it currently only allow message and title, there does not seems to be any way to pass the overriding option to toastr at moment.

My specific usage is for some notification, I want to make to stick (not auto dismiss), while for most other notification I still do want them to auto dismiss.

Thank you very much

Add FastBoot support

Currently it conflicts when running an app with FastBoot.

TypeError: Cannot set property 'options' of undefined
    at initialize (/Users/myUser/Projects/bazaar/tmp/broccoli_merge_trees-output_path-DFpRGlMk.tmp/assets/addon-tree-output/ember-toastr/initializers/toastr.js:6:1)
    at Object.initialize (/Users/myUser/Projects/bazaar/tmp/broccoli_merge_trees-output_path-DFpRGlMk.tmp/assets/bazaar/initializers/toastr.js:45:1)
    at /Users/myUser/Projects/bazaar/tmp/broccoli_merge_trees-output_path-DFpRGlMk.tmp/assets/ember-application/system/engine.js:88:1
    at Vertices.each (/Users/myUser/Projects/bazaar/tmp/broccoli_merge_trees-output_path-DFpRGlMk.tmp/assets/dag-map.js:188:1)
    at Vertices.walk (/Users/myUser/Projects/bazaar/tmp/broccoli_merge_trees-output_path-DFpRGlMk.tmp/assets/dag-map.js:117:1)
    at DAG.each (/Users/myUser/Projects/bazaar/tmp/broccoli_merge_trees-output_path-DFpRGlMk.tmp/assets/dag-map.js:62:1)
    at DAG.topsort (/Users/myUser/Projects/bazaar/tmp/broccoli_merge_trees-output_path-DFpRGlMk.tmp/assets/dag-map.js:68:1)
    at Class._runInitializer (/Users/myUser/Projects/bazaar/tmp/broccoli_merge_trees-output_path-DFpRGlMk.tmp/assets/ember-application/system/engine.js:110:1)
    at Class.runInitializers (/Users/myUser/Projects/bazaar/tmp/broccoli_merge_trees-output_path-DFpRGlMk.tmp/assets/ember-application/system/engine.js:75:1)
    at Class._bootSync (/Users/myUser/Projects/bazaar/tmp/broccoli_merge_trees-output_path-DFpRGlMk.tmp/assets/ember-application/system/application.js:391:1)
    at Class.boot (/Users/myUser/Projects/bazaar/tmp/broccoli_merge_trees-output_path-DFpRGlMk.tmp/assets/ember-application/system/application.js:370:1)
    at EmberApp.buildAppInstance (/Users/myUser/Projects/bazaar/node_modules/fastboot/src/ember-app.js:205:21)
    at EmberApp.visitRoute (/Users/myUser/Projects/bazaar/node_modules/fastboot/src/ember-app.js:232:17)
    at EmberApp.visit (/Users/myUser/Projects/bazaar/node_modules/fastboot/src/ember-app.js:301:17)
    at FastBoot.visit (/Users/myUser/Projects/bazaar/node_modules/fastboot/src/index.js:79:22)
    at /Users/myUser/Projects/bazaar/node_modules/fastboot-express-middleware/src/index.js:31:14
    at app.use (/Users/myUser/Projects/bazaar/node_modules/ember-cli-fastboot/index.js:299:11)
    at Layer.handle [as handle_request] (/Users/myUser/Projects/bazaar/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/Users/myUser/Projects/bazaar/node_modules/express/lib/router/index.js:317:13)
    at /Users/myUser/Projects/bazaar/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/Users/myUser/Projects/bazaar/node_modules/express/lib/router/index.js:335:12)
    at next (/Users/myUser/Projects/bazaar/node_modules/express/lib/router/index.js:275:10)
    at err (/Users/myUser/Projects/bazaar/node_modules/ember-cli/lib/tasks/server/middleware/broccoli-watcher/index.js:54:11)
    at watcher.then (/Users/myUser/Projects/bazaar/node_modules/broccoli-middleware/lib/watcher-middleware.js:35:7)
    at tryCatch (/Users/myUser/Projects/bazaar/node_modules/rsvp/dist/lib/rsvp/-internal.js:198:12)
    at invokeCallback (/Users/myUser/Projects/bazaar/node_modules/rsvp/dist/lib/rsvp/-internal.js:211:13)
    at /Users/myUser/Projects/bazaar/node_modules/rsvp/dist/lib/rsvp/then.js:26:14
    at flush (/Users/myUser/Projects/bazaar/node_modules/rsvp/dist/lib/rsvp/asap.js:80:5)
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)

module unification support? / this.get('toast') is undefined

was trying to use this library, but I get

Error while processing route: setup.introduction Assertion Failed: Attempting to inject an unknown injection: 'service:toast' Error: Assertion Failed: Attempting to inject an unknown injection: 'service:toast'

Edit / Update

not sure what I did to get rid of the service:toast unknown injection issue.

but now this.get('toast') is undefined

Default service name does not play well with liquid-fire

Hi,

I just installed ember-toastr and it works nicely so far. However, with the default service name "notify" it crashes when I use liquid-fire. I changed it in the environment.js to injectAs: "toast" and now it works. So, this is quite easily fixable, but I guess it would be nice to choose another default service name, because liquid-fire is a quite popular ember addon, and it is kind of confusing if you install the addon and suddenly nothing works anymore.

How to test?

What's the proper way to test Toast messages in Acceptance/Integration tests?

I tried the way ember-cli-flash does it, but the messages never show up while tests are runnin. Any ideas? Thanks!!

Options not working in 2.0.0

Hi,

First things first: thanks for the great add-on!

Now for the whining :-)

I just upgraded from 1.7.2 to 2.0.0. Was kinda surprised when I didn't see anything at all, but then I RTFM'ed and saw that ember-toastr was no longer auto-injected into routes, controllers, components. So I added the appropriate "inject" statements and all was well.

Except for the appearance and position of the message. I have always had it displayed at the bottom center of the page, along with a progress-bar and close-button. Now it appears at the top-right, without both the progress-bar and close-button. I have attached a screenshot so you can see.

Here is what I have in my environment.js file. The only recent addition was the injectAs: 'toast', which wasn't really needed because that is how I referenced it in my code. But I thought maybe adding it would help... but it did not.

Anyway, here are the settings, which have worked for at least a year:

`

ENV['ember-toastr'] = {
injectAs: 'toast',
toastrOptions: {
progressBar: true,
closeButton: true,
positionClass: 'toast-bottom-center'
}
};
`

Any thoughts as to how I can get it back down to the bottom center, along with the progress-bar and close-button?

Thanks,
Larry
Screenshot from 2019-10-10 16-46-52

Error when using fastboot

When I start the app with fastboot, I have this error message :

/tmp/broccoli-13095zIWfokgP5Vdm/out-390-broccoli_merge_trees/assets/vendor.js:252
    throw new Error('Could not find module `' + id + '` imported from `' + referrer + '`');
    ^

Error: Could not find module `jquery` imported from `(require)`
    at missingModule (/tmp/broccoli-13095zIWfokgP5Vdm/out-390-broccoli_merge_trees/assets/vendor/loader/loader.js:247:1)
    at findModule (/tmp/broccoli-13095zIWfokgP5Vdm/out-390-broccoli_merge_trees/assets/vendor/loader/loader.js:258:1)
    at requireModule (/tmp/broccoli-13095zIWfokgP5Vdm/out-390-broccoli_merge_trees/assets/vendor/loader/loader.js:24:1)
    at /tmp/broccoli-13095zIWfokgP5Vdm/out-390-broccoli_merge_trees/assets/vendor/toastr/toastr.js:472:1
    at /tmp/broccoli-13095zIWfokgP5Vdm/out-390-broccoli_merge_trees/assets/vendor/toastr/toastr.js:15:1
    at /tmp/broccoli-13095zIWfokgP5Vdm/out-390-broccoli_merge_trees/assets/vendor/toastr/toastr.js:470:1
    at Script.runInContext (vm.js:107:20)
    at VMSandbox.eval (/workspace/form/frontend/node_modules/fastboot/src/vm-sandbox.js:14:16)
    at /workspace/form/frontend/node_modules/fastboot/src/ember-app.js:156:15
    at Array.forEach (<anonymous>)
    at EmberApp.loadAppFiles (/workspace/form/frontend/node_modules/fastboot/src/ember-app.js:153:21)
    at EmberApp.retrieveSandboxedApp (/workspace/form/frontend/node_modules/fastboot/src/ember-app.js:201:10)
    at new EmberApp (/workspace/form/frontend/node_modules/fastboot/src/ember-app.js:59:21)
    at FastBoot._buildEmberApp (/workspace/form/frontend/node_modules/fastboot/src/index.js:114:17)
    at new FastBoot (/workspace/form/frontend/node_modules/fastboot/src/index.js:52:10)
    at app.use (/workspace/form/frontend/node_modules/ember-cli-fastboot/index.js:319:29)
    at Layer.handle [as handle_request] (/workspace/form/frontend/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/workspace/form/frontend/node_modules/express/lib/router/index.js:317:13)
    at /workspace/form/frontend/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/workspace/form/frontend/node_modules/express/lib/router/index.js:335:12)
    at next (/workspace/form/frontend/node_modules/express/lib/router/index.js:275:10)
    at err (/workspace/form/frontend/node_modules/ember-cli/lib/tasks/server/middleware/broccoli-watcher/index.js:54:11)
    at watcher.then (/workspace/form/frontend/node_modules/broccoli-middleware/lib/watcher-middleware.js:35:7)
    at tryCatcher (/workspace/form/frontend/node_modules/ember-cli/node_modules/rsvp/dist/lib/rsvp/-internal.js:39:19)
    at invokeCallback (/workspace/form/frontend/node_modules/ember-cli/node_modules/rsvp/dist/lib/rsvp/-internal.js:211:31)
    at /workspace/form/frontend/node_modules/ember-cli/node_modules/rsvp/dist/lib/rsvp/then.js:26:14
    at flush (/workspace/form/frontend/node_modules/ember-cli/node_modules/rsvp/dist/lib/rsvp/asap.js:80:5)
    at process._tickCallback (internal/process/next_tick.js:61:11)

It works well when fastboot is disabled.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.