npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@singularsystems/neo-notifications

v1.1.3

Published

Client for the neo notifications server.

Downloads

165

Readme

neo-notifications

Back to Index

This project contains the client code for the neo notification server.

Notification hub

The notification signalr client will display user popup notifications sent to the notification server.

Templating UI

The templating UI allows users to edit the templates defined on the notification server.

Config

  • Register the notifications module in your app startup code:
import { NotificationServiceModule } from '@singularsystems/neo-notifications';

appService.registerModule(NotificationServiceModule);
  • Add a notification config property to your app config:

public get notificationServerConfig(): INotificationServiceConfig {
    return {
        basePath: this.notificationServer.basePath,
        apiPath: this.notificationServer.basePath + "/api",
        popupHideTime: 4,
        appId: 1,
        allowBodyHtml: false
    }
}
  • Register the config with DI in your app module:
// Where AppConfig is your main app config model.
container.bindConfig(NotificationServiceTypes.ConfigModel, (c: AppConfig) => c.notificationServerConfig);
  • Initialise the notification service after user login:
// Add this to your authentication service:
protected afterUserLoaded() {
    AppService.get(NotificationServiceTypes.Services.NotificationService).initialise();
}

Override services

The service which creates the popup notifications is called NotificationPopupCreator. By default this adds a notification to the global notifications list, which results in a toast being shown.

You can override this by implementing your own INotificationPopupCreator or by creating a subclass of NotificationPopupCreator.

Register the new implementation in your startup code:

container.bind(NotificationServiceTypes.Services.NotificationPopupCreator).to(MyNotificationPopupCreator).inSingletonScope();

Components

This package contains the following components:

  • TemplateLayoutsView - Lists all the template layouts which have been registered, and allows the user to override the layout by tenant / culture.
  • TemplatesView - Lists all the template types which have been registered, and allows the user to override the template type by tenant / culture.
  • NotificationSettings - View, Modal and component to allow editing of notification settings.
  • EditTemplateComponent - This allows you to show the edit template ui in your page (for a specific template type and record id).
  • EditTemplateModal - This displays the EditTemplateComponent in a modal.
  • NotificationsView - Allows the user to search for notifications which have been queued / sent.
  • HtmlView - Use this to show output html. Do NOT output html directly using innerHtml or dangerouslySetInnerHTML.

TemplateLayoutsView / TemplatesView

To add these view to your main menu, import the views into your routes file, and create menu items for them.

import { TemplateLayoutsView, TemplatesView } from '@singularsystems/neo-notifications';

EditTemplateComponent

To use this component in your view, create an instance of TemplatesVM, passing in the task runner from your view. When you need to load the template for your record, call initialise on the VM.

public templatesVM = new TemplatesVM(this.taskRunner);

editTemplate() {
    this.templatesVM.initialise("MyTemplateType", this.recordId);
}

In your UI, pass the view model to the edit template component:

<EditTemplateComponent viewModel={this.templatesVM} />

TemplatesVM has an afterSave property which you can set to be notified once the template has been saved by the user.

If you want to control saving of the template, you can set the hideSave prop.

EditTemplateModal

<EditTemplateModal viewModel={this.templatesVM} />

This component also accepts a TemplatesVM via the viewModel prop. To show the modal, call initialise on the VM. (See the EditTemplateComponent section for details). The modal will be dismissed if the user clicks close, or saves the template.

Styles

Import the notification style sheet into your main scss file:

@import "~@singularsystems/neo-notifications/styles/notifications.scss";

Server messages

When sending a popup notification to a user, you may want to also send a signal message to your view model to perform some action such as refreshing the page.

To subscribe to one of these messages in your view model, inject the ServerMessageSubscriber service in your view model constructor:

serverMessageSubscriber = AppService.get(Neo.Messaging.ServerMessageSubscriber)

Also in the constructor, subscribe to incoming messages by calling the subscribe method, passing in a key which differentiates this process from any others you may have in your app:

this.autoDispose(serverMessageSubscriber.subscribe("my-key", this.messageReceived.bind(this)));

The callback method will be passed whatever data you sent from the server. E.g:

// Simple value
private messageReceived(id: number) {

}

// Or custom object
private messageReceived(message: IMyCustomMessage) {

}

Server side

You can send a process message to the server either by creating a process message recipient:

Recipient.ProcessMessageRecipient(UserGuid, "my-key", id);

Or by adding a process message to a recipient:

Recipient.PopupRecipient(UserGuid, new PopupData() {...}).WithProcessMessage("my-key", id);

When using the above recipient type, the SendNotificationsAsync method on the notifications service will send a process message in addition to a popup message / email / sms.

If you want to only send a process message, use

NotificationService.SendProcessMessageAsync(
    Recipient.ProcessMessageRecipient(UserGuid, "my-key", idOrObject))