Giter Club home page Giter Club logo

ng-notifications-bar's Introduction

ng-notifications-bar

Angular.js and Animate.css based component for stylish and flexible application notifications.

Demo

Overview

Web applications requires notify users of ongoing events. Common cases are errors, successful completion notifications etc. With ng-notifications-bar it's as easy as,

<body>
	<notifications-bar class="notifications"></notifications-bar>
	...

Installation

Npm installation,

$ npm install ng-notifications-bar --save

Or bower installation,

$ bower install ng-notifications-bar --save

Update your scripts and styles section or use the require for browserified applications.

<link rel="stylesheet" href="bower_components/ng-notifications-bar/dist/ngNotificationsBar.min.css" />
<script src="bower_components/angular-sanitize/angular-sanitize.js"></script>
<script src="bower_components/ng-notifications-bar/dist/ngNotificationsBar.min.js"></script>

If you use Grunt, wiredep should inject the required angular-sanitize.js for you.

For browserify applications, require module in yours application module,

require('ng-notifications-bar');

In case you are using sass in project, it's possible to just import ngNotificationsBar styles,

@import "../../node_modules/ng-notifications-bar/sass/ngNotificationsBar";

In application module,

angular.module('app', ['ngNotificationsBar', 'ngSanitize']);

ngSanitize can be omitted if HTML support isn't needed.

API

The module consists of there elements - directive, service and provider.

Directive

notifications-bar element directive, should be placed once, typically right after <body> open tag.

<notifications-bar class="notifications"></notifications-bar>

If you are using a icon library besides Glyphicons for the close button (such as Font Awesome), include a closeIcon attribute.

<notifications-bar class="notifications" closeIcon="fa fa-times-circle"></notifications-bar>

The default is the glyphicon-remove icon so don't forget to import Glyphicons if you aren't defining a closeIcon attribute.

Possible to use as attribute, as well

<div notifications-bar class="notifications"></div notifications-bar>

Service

notification service is used by controllers (or other directives), to show notifications.

app.controllers('app', function ($scope, api, notifications) {
	api.get({resource: 'tasks'})
		.then(function (tasks) {
			$scope.tasks = tasks;
		}, function (error) {
			notifications.showError({message: error.message});
		});

	$scope.submitTask = function () {
		api.post({resource: 'tasks'}, {description: this.description})
			.then(function () {
				notifications.showSuccess({message: 'Your task posted successfully'});
			}, function (error) {
				notifications.showError({message: 'Oh no! Task submission failed, <em>please try again.</em>'});
			});
	}
});

Provider

notificationsConfigProvider is used to override some notifications bar defaults.

app.config(['notificationsConfigProvider', function (notificationsConfigProvider) {
	// auto hide
	notificationsConfigProvider.setAutoHide(true)

	// delay before hide
	notificationsConfigProvider.setHideDelay(3000)
}])

Settings

It is possible to setup the whole notifications bar module in module config and each notification separately in controller

Available options:

  • autoHide
  • hideDelay
  • acceptHTML
  • autoHideAnimation
  • autoHideAniationDelay

Please note, HTML support is only configurable at a global level. If HTML is to be supported, make sure to inject the 'ngSanitize' dependency.

var app = angular.module('app', ['ngNotificationsBar', 'ngSanitize']);

During configuration

app.config(['notificationsConfigProvider'], function (notificationsConfigProvider) {
	// auto hide
	notificationsConfigProvider.setAutoHide(true);

	// delay before hide
	notificationsConfigProvider.setHideDelay(3000);

	// support HTML
	notificationsConfigProvider.setAcceptHTML(false);
	
	// Set an animation for hiding the notification
	notificationsConfigProvider.setAutoHideAnimation('fadeOutNotifications');
	
	// delay between animation and removing the nofitication
	notificationsConfigProvider.setAutoHideAnimationDelay(1200);
	
}])

Override in controller

app.controller('main', function ($scope, notifications) {
	$scope.showError = function () {
		notifications.showError({
			message: 'Oops! Something bad just happened! (hides faster)',
			hideDelay: 1500, //ms
			hide: true //bool
		});
	};
});

Development

Install bower dependencies,

$ bower install

Install npm dependencies,

$ npm install

Run grunt build,

$ grunt

as result, /dist folder is created with ready to use .js and .css file.

Project doesn't have tests at the moment, so run example and check the functionality,

$ grunt start:example

Licence

Copyright (c) 2014, [email protected]

MIT

ng-notifications-bar's People

Contributors

4141done avatar alexbeletsky avatar ascension avatar davewalk avatar dmaslov avatar donaldpcook avatar fagnercarvalho avatar konstantinyegupov avatar oaleynik avatar psanzay avatar seanhussey avatar superxp1412 avatar tbehunin avatar tommaitland avatar unr 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ng-notifications-bar's Issues

"notifications is not defined". Will not work with browserify-shim

I am trying to get ng-notifications-bar to work with browserify-shim, but am unable to. I am requiring it in my app:

require('angular').module('admin', [
  require('angular-loading-bar'),
  require('angular-ui-router'),
  require('angular-ui-bootstrap'),
  require('bootstrap-ui-datetime-picker'),
  require('angular-bootstrap-show-errors'),
  require('angular-cookies'),
  require('angular-breadcrumb'),
  require('angular-resource'),
  require('angular-sanitize'),
  require('ui-select'),
  require('ngmap'),
  require('ng-notifications-bar'),
  require('textAngular')
])

And it is also included in my package.json file as a dependency and within browser, browserify-shim.

  "browser": {
    "angular": "./node_modules/angular/angular.js",
    "ng-notifications-bar": "./node_modules/ng-notifications-bar/src/ngNotificationsBar.js"
  },
  "browserify-shim": {
    "angular": {
      "exports": "angular"
    },
    "ng-notifications-bar": {
      "depends": [
        "./node_modules/angular/angular.js:angular"
      ],
      "exports": "angular.module('ngNotificationsBar').name"
    }

Any thoughts on getting this working?

Use $cookieStore to save prevent notifications a user has already dismissed / closed

Use $cookieStore to save prevent notifications a user has already dismissed / closed

  • This has a config spot in the provider (getSaveResponse, setSaveResponse)
  • Add a provider config option for the cookies prefix value
  • validate that a notification with saveResponse also has a id parameter. This was needed to find * correspond correct notifications for dismissal.

Decouple glyphicons

Decouple glyphicons. Fairly straight forward. I was using font awesome and needed to change the template because of this. The close icon doesn't need to be library specific. Maybe add a way to customize it?

Sub-task of #15.

Enhancement: remove previous notifications

Hey there, first of all, great component ! thanks for the hard work.

I'd like to propose one enhancement: the ability to remove existing notifications before adding a new one.
Basically the component would only allow one notification at the time. Right now I can add several notifications and they stack on top of each other.
The way we could do it is restrict the number of notifications visible in the same time. If the number goes over the limit, the oldest notification would be removed, until reaching the limit again.

I'm thinking about adding one setting option: maxVisibleNotifications
This could be a parameter in the provider:

app.config(['notificationsConfigProvider', function (notificationsConfigProvider) {
    // max visible notifications
    notificationsConfigProvider.setMaxVisibleNotifications(1);
}]);

I'm currently too busy to take care of it & pull a request, but I will once I can. I just wanted to throw the idea out there.

Thanks

Angular is not defined

Got an error when using this with requireJS

Fixed it as follows, not sure if this is the best way to go about it however:

angular = angular | window.angular

Possible Enhancements

Before continuing before I want to say this was far and away the best notification module I found during my research. Given that I needed to modify it quite substantially I wanted to also praise the code quality because it took barely any time to grasp everything.

Unfortunately, I did run into issues and I would like to share my cases for possible enhancements to the main code base.

  • Use $cookieStore to save prevent notifications a user has already dismissed / closed
    • This has a config spot in the provider (getSaveResponse, setSaveResponse)
    • Add a provider config option for the cookies prefix value
    • validate that a notification with saveResponse also has a id parameter. This was needed to find correspond correct notifications for dismissal.
  • Give the ability to modify the template or provide a custom one through either transclude or template-url attribute.
  • Decouple glyphicons. Fairly straight forward. I was using font awesome and needed to change the template because of this. The close icon doesn't need to be library specific. Maybe add a way to customize it?
  • Add a notification class to each notification div in the template along with the note.type.
    • This is a minor one because I just wanted to use a selector like .notification to target each entire notification. I could have used a child selector, but it just seemed like overkill for a html element that was a notification.

Let me know what your thoughts are. The template things are fairly opinionated for myself, but I do believe they are all good features.

Show limited numbers of notifications

How to limit the number of occurrence of the notifications? There is a feature already to implement this or should I treat this in my Controller for example?

Some of notifications stay forever

When I show more than one notification, sometimes some of them stay forever even if hide : true. I know it might be little information but please try to reproduce. Thanks.

typo in README

Hi!
I think you have a typo in Services section in README file.
The name of component's factory is notificationS, but in your example the name is notification
app.controllers('app', function ($scope, api, notification) {

And getting an error:

Error: [$injector:unpr] Unknown provider: notificationProvider <- notification

Use versions

Could you please use some versions in the file description or maybe tags for repository? It would be much easier to track when it needs some updates :)

Instructions on how to contribute

I have a small fix to make a pull request, but I suspect there are some steps to "compile" the library or something.

Could you post a small guide on how to do this?

thanks.

Add Bottom Bar Feature

Hi,

I love this notifications so much.

I've a little idea for your next improvement.

Make a config for show the notification at the bottom. Sometimes bottom is look better than top :p.

Thanks!

Error: $injector:modulerr Module Error

Hi, I've ben trying to setup the notification var for a couple of hours, i get a
๐Ÿ‘ Error: $injector:modulerr Module Error whenever i refresh the page.

imports:

<script src="bower_components/angular-sanitize/angular-sanitize.js"></script>
<script scr="bower_components/ng-notifications-bar/dist/ngNotificationsBar.min.js"></script>

var module = angular.module('app', ['onsen', 'ngResource', 'ngCordova', 'lbServices', 'vxWamp', 'LocalForageModule', 'angucomplete-alt', 'ngSanitize','ngNotificationsBar']);

image

image
image

typo in css

glyphicons-halflings-regular.woof - glyphicons-halflings-regular.woff

Not available on Bower

Hey man, great project! Tried installing using the command in the README no luck, also tried to look it up on Bower and could not find it!

How to add own HTML and specify setAutoHideAnimation property

I'm doing:
notificationsConfigProvider.setAutoHideAnimation('fadeOutNotifications');
notificationsConfigProvider.setAutoHideAnimationDelay(15 * 1000);
But I don;t see any animations at hide time when I'm running the example.

Also is there a way to specify own HTML for message? When notificationsConfigProvider.setAcceptHTML(true), can I put in any HTML or it has limited capabilities.

Notification styling issues browserify + browserify-shim

I have installed ng-notifications-bar and successfully created a notification, and was able to style the notifications, but now the message is separated from the notification. Two bars appear. One is white and one is the color of the notification. The white bar contains the message and the colored bar is beneath it. Here is my installation.

Package.json

  "browser": {
    "angular": "./node_modules/angular/angular.js",
    "angular-breadcrumb": "./node_modules/angular-breadcrumb/release/angular-breadcrumb.js",
    "bootstrap-ui-datetime-picker": "./node_modules/bootstrap-ui-datetime-picker/dist/datetime-picker.js",
    "angular-bootstrap-show-errors": "./node_modules/angular-bootstrap-show-errors/src/showErrors.js",
    "ng-notifications-bar": "./node_modules/ng-notifications-bar/src/ngNotificationsBar.js"
  },
  "browserify-shim": {
    "angular": {
      "exports": "angular"
    },
    "angular-breadcrumb": {
      "depends": [
        "./node_modules/angular/angular.js:angular"
      ],
      "exports": "angular.module('ncy-angular-breadcrumb').name"
    },
    "bootstrap-ui-datetime-picker": {
      "depends": [
        "./node_modules/angular/angular.js:angular"
      ],
      "exports": "angular.module('ui.bootstrap.datetimepicker').name"
    },
    "angular-bootstrap-show-errors": {
      "depends": [
        "./node_modules/angular/angular.js:angular"
      ],
      "exports": "angular.module('ui.bootstrap.showErrors').name"
    },
    "ng-notifications-bar": {
      "depends": [
        "./node_modules/angular/angular.js:angular"
      ],
      "exports": "angular.module('ngNotificationsBar').name"
    }
  },

I have required ng-notifications-bar in my app:

require('angular').module('admin', [
  require('angular-loading-bar'),
  require('angular-ui-router'),
  require('angular-ui-bootstrap'),
  require('bootstrap-ui-datetime-picker'),
  require('angular-bootstrap-show-errors'),
  require('angular-cookies'),
  require('angular-breadcrumb'),
  require('angular-resource'),
  require('angular-sanitize'),
  require('ui-select'),
  require('ngmap'),
  require('ng-notifications-bar'),
  require('textAngular')
])

I imported the styling using:
@import (less) "/node_modules/ng-notifications-bar/css/ngNotificationsBar.css";

Do you know why this would happen? Here is an image of what it looks like:

fullscreen_10_3_16__2_07_am

Is there an option to customize the background color of various notification types?

Hi,

Is there a way to add custom color/ class to the various notification options?

notifications.showError({
    message: 'Oops! Something bad just happened! (hides faster)',
    hideDelay: 1500, //ms
    hide: true //bool
    class: "custom-class" // With this, i could give different color schemes.
});

p.s: I love the color scheme, but this would standout way too much in my current application and hence i would love to have a feature where the class could be altered so that it can be tonned down a bit.

Cheers.
Roy

Enhancement: Fadeout for removed items

As an enhancement, it would be nice to see the notification fade out before being removed from the notification array. Maybe we want to apply a notification-exit animation. And once it finishes, remove it from the notification list.

Show notification without animation

Hi and congratulations for this nice directive. Great job.

I would like to show a notification bar whitout any animation. Is there an easy way to do it? I was reading the docs and as far as I know there isn't, but parhaps I'm wrong.

Thanks.

Typo in README.md

Note that the closing square bracket ] appears twice below (first appearance should be removed):

app.config(['notificationsConfigProvider'], function (notificationsConfigProvider) {
    // auto hide
    notificationsConfigProvider.setAutoHide(true)

    // delay before hide
    notificationsConfigProvider.setHideDelay(3000)
}])

cycling messages

Hello, thank you for this library.
Is it possible to 'cycle' messages instead of stacking them? In other words, I want to supply it an array of, say, 3 elements and have it cycle through them inside the same display bar.

thank you.

Close icon font-size disproportionate

The close icon font-size is 12px and the notification text is 18px. By default, it looks very disproportionate side-by-side (as seen when using font awesome icons). If you simply change the .notifications .close-click style in ngNotificationsBar.css to font-size: inherit;, the icon would look more uniform and proportional to the notification text. I tried to submit a pull request for this but didn't have permissions apparently.

Set `autoHide` option to config

At the moment we have to pass hide option to message functions. Instead, it will be great to have setAutoHide through the directive config.

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.