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

ninjagoat-dashboard

v0.4.0

Published

Ninjagoat bindings for a dashboard component (backed by [react-grid-layout](https://github.com/STRML/react-grid-layout)).

Downloads

9

Readme

Ninjagoat-dashboard

Ninjagoat bindings for a dashboard component (backed by react-grid-layout).

Installation

$ npm install ninjagoat-dashboard

Register the module with ninjagoat

//bootstrapper.ts
import {DashboardModule} from "ninjagoat-dashboard";

application.register(new DashboardModule())

Usage

Start by adding a distinct list of the widgets available in the application.

import {IWidgetEntry} from "ninjagoat-dashboard";

container.bind<IWidgetEntry<WidgetModel>>("IWidgetEntry").toConstantValue({
    construct: WidgetViewModel,
    observable: (context) => Observable.just(context.parameters),
    name: "widget-1",
    sizes: ["small", "large"]
});

container.bind<IWidgetEntry<WidgetModel>>("IWidgetEntry").toConstantValue({
    construct: Widget2ViewModel,
    observable: (context) => Observable.just(context.parameters),
    name: "widget-2",
    sizes: ["small", "large"]
});

Add the dashboard viewmodel to the registry using a specific model retriever.

import {DashboardViewModel, DashboardModelRetriever} from "ninjagoat-dashboard";

let dashboardModelRetriever = serviceLocator.get<DashboardModelRetriever>("DashboardModelRetriever");

registry.add(DashboardViewModel, context => dashboardModelRetriever.modelFor(context))
        .forArea("Dashboard");

You can then implement the widgets viewmodels and proceed for the view part.

import * as React from "react";
import {View} from "ninjagoat";
import {DashboardViewModel, Dashboard, Card} from "ninjagoat-dashboard";

class DashboardView extends View<DashboardViewModel> {

    render() {
        let dashboardVm = this.props.viewmodel;
        return (
            <Dashboard config={dashboardVm.config} events={dashboardVm} widgets={dashboardVm.widgets}
                       templateSelector={(item) => {
                //Here you can set which template to use for a given widget
                let widgetName = item[0].name;
                switch (widgetName) {
                    case "widget-1":
                        return <Widget item={item} widgetManager={dashboardVm} />;
                    case "widget-2":
                        //Return widget-2 template;
                        break;
                    default:
                        return <div></div>;
                }
            }}/>
        );
    }
}

The widget view can be implemented with the convenient abstract class WidgetView. Here's a simple implementation of it that uses a Card view (to add a title and dragging behaviour) and the widget manager to alter the dashboard state.

class Widget extends WidgetView<WidgetViewModel, WidgetModel> {
    render() {
        return <Card title={"Widget"}>
            <button onClick={() => this.widgetManager.remove(this.settings.id)}>Close</button>
            <button onClick={() => this.widgetManager.configure(this.settings.id)}>Configure</button>
            <button onClick={() => this.widgetManager.resize(this.settings.id, "large")}>Make large</button>
            <button onClick={() => this.widgetManager.resize(this.settings.id, "small")}>Make small</button>
        </Card>
    }
}

Access the registered widgets

An "entries" property is available on the DashboardViewModel to access the dictionary of widgets. Alternatively you can use a @multiInject for the entries.

constructor(@multiInject("IWidgetEntry") entries:IWidgetEntry<any>) {
 //Do something with the widgets   
}

Showing a dialog with the widgets catalogue

Extends the DashboardViewModel and call ninjagoat-dialogs with the widgets list, then what is done inside the dialog is up to you.

import {DashboardViewModel} from "ninjagoat-dashboard";
import {inject, multiInject, optional} from "inversify";
import {IViewModelFactory, IViewModelRegistry, ViewModel} from "ninjagoat";
import {IWidgetEntry, IDashboardConfig, DefaultDashboardConfig, IWidgetManagerFactory} from "ninjagoat-dashboard";
import {IDialogService, DialogStatus} from "ninjagoat-dialogs";

@ViewModel("Dashboard")
class CustomDashboardViewModel extends DashboardViewModel {

    constructor(@multiInject("IWidgetEntry") widgets: IWidgetEntry<any>[],
                @inject("IViewModelFactory") viewmodelFactory: IViewModelFactory,
                @inject("IWidgetManagerFactory") widgetManagerFactory: IWidgetManagerFactory,
                @inject("IViewModelRegistry") registry: IViewModelRegistry,
                @inject("IDashboardConfig") @optional() config: IDashboardConfig = new DefaultDashboardConfig(),
                @inject("IDialogService") private dialogService: IDialogService,) {
        super(widgets, viewmodelFactory, widgetManagerFactory, registry, config);
    }

    showWidgetsCatalogue() {
        let dialogData = {
            widgets: this.entries,
            selectedWidget: null,
            selectedSize: null
        };
        this.dialogService.display("your_widgets_catalogue_dialog_id", dialogData, null).then((status: DialogStatus) => {
            //Selected widget and size is populated inside the dialog
            if (status === DialogStatus.Confirmed && dialogData.selectedWidget) {
                this.add(dialogData.selectedWidget, dialogData.selectedSize);
            }
        });
    }
}

Configurable widget

A given widget can be configured if its viewmodel implement the IConfigurableWidget interface.

export interface IConfigurableWidget<T> {
    configure(): Promise<T>;
}

For example, if you need a parameter in order to make the widget works (e.g. a city in a weather widget), you can trigger a dialog for the selection of the city, then returning the value in the promise of the configure method. That value is saved and then used as a parameter to build the viewmodel's observable.

Multi dashboard

Multi dashboard is done by specific the name field when retrieving the dashboard model.

registry.add(DashboardViewModel, context => {
    context.parameters.name = "my-custom-dashboard"; //Use a parametric field in the router to populate it automatically
    return dashboardModelRetriever.modelFor(context);
}).forArea("Dashboard");

License

Copyright 2016 Tierra SpA

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.