# @hawtio/core

> [![Test](https://github.com/hawtio/hawtio-core/actions/workflows/test.yml/badge.svg)](https://github.com/hawtio/hawtio-core/actions/workflows/test.yml)

Latest version **4.16.5** (published 2023-04-07) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @hawtio/core
pnpm add @hawtio/core
yarn add @hawtio/core
bun add @hawtio/core
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.16.5 |
| Published | 2023-04-07 |
| First published | 2017-05-29 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 18 |
| Unpacked size | 3.1 MB |
| Known vulnerabilities | 0 (+20 in 4 direct dependencies) |
| Install scripts | no |
| GitHub stars | 12 |
| Maintainers | gr.grzybek, astefanutti, akieling, tadayosi, gashcrumb, jamesnetherton |

## Links

- npm: https://www.npmjs.com/package/@hawtio/core
- Repository: https://github.com/hawtio/hawtio-core
- npm.io page: https://npm.io/package/@hawtio/core

## Dependencies (18)

- [urijs](https://npm.io/package/urijs.md) ^1.19.9
- [jquery](https://npm.io/package/jquery.md) 2.2.4
- [lodash](https://npm.io/package/lodash.md) ~4.17.21
- [marked](https://npm.io/package/marked.md) 0.6.1
- [angular](https://npm.io/package/angular.md) ^1.8.0
- [js-logger](https://npm.io/package/js-logger.md) ^1.6.0
- [typescript](https://npm.io/package/typescript.md) ^3.0.3
- [@types/urijs](https://npm.io/package/@types/urijs.md) ~1.15.38
- [@types/jquery](https://npm.io/package/@types/jquery.md) 2.0.53
- [@types/lodash](https://npm.io/package/@types/lodash.md) ^4.0.0
- [@types/marked](https://npm.io/package/@types/marked.md) 0.6.0
- [angular-route](https://npm.io/package/angular-route.md) ^1.7.7
- [@types/angular](https://npm.io/package/@types/angular.md) *
- [@types/jasmine](https://npm.io/package/@types/jasmine.md) ~2.8.0
- [@hawtio/core-dts](https://npm.io/package/@hawtio/core-dts.md) ~3.3.0
- [angular-patternfly](https://npm.io/package/angular-patternfly.md) ^5.0.0
- [@types/angular-route](https://npm.io/package/@types/angular-route.md) *
- [@patternfly/patternfly](https://npm.io/package/@patternfly/patternfly.md) ^2.0.0

## Recent versions

- 4.16.5 (latest) — 2023-04-07
- 4.16.4 — 2022-08-24
- 4.16.3 — 2022-07-26
- 4.16.2 — 2022-07-15
- 4.16.1 — 2022-05-10
- 4.16.0 — 2022-03-03
- 4.15.3 — 2021-12-10
- 4.15.2 — 2021-12-10
- 4.15.1 — 2021-12-10
- 4.15.0 — 2021-09-24
- 4.14.2 — 2021-06-25
- 4.14.1 — 2021-02-02
- 4.14.0 — 2020-09-09
- 4.13.1 — 2020-08-25
- 4.13.0 — 2020-04-10
- … 97 more at https://npm.io/package/@hawtio/core/versions

## README

# Hawtio Core

[![Test](https://github.com/hawtio/hawtio-core/actions/workflows/test.yml/badge.svg)](https://github.com/hawtio/hawtio-core/actions/workflows/test.yml)

This package contains the core parts of the **[Hawtio](http://hawt.io)** web console.

hawtio-core features include:

1. [Plugins](#plugins)
2. [Routing and navigation](#routing-and-navigation)
3. [Help documentation](#help-documentation)
4. [UI extensions](#ui-extensions)
5. [Template caching](#template-caching)

## Plugins

### Registering inline plugins

Register any AngularJS modules you want to load using `hawtioPluginLoader` in your code. For example:

```javascript
  export const myModule = angular
    .module('my-module', [])
    .name;

  hawtioPluginLoader.addModule(myModule);
```

By default hawtio-core already adds `ng`, `ng-route` and `ng-sanitize`.

### Registering plugins dynamically

Plugins can also be dynamically discovered by registering URLs to check with `hawtioPluginLoader.addUrl()`. The URL should return a map of json objects that contain scripts for the plugin loader to load. For example:

```json
{
  "some_plugin": {
    "Name": "dummy",
    "Context": "/hawtio",
    "Scripts": [
      "test.js"
    ]
  }
}
```

Where we've the following attributes:

* **Name** - The name of the plugin
* **Scripts** - An array of script files that should be loaded
* **Context** - the top level context under which all scripts reside

Remove any ng-app annotation from your HTML template, hawtio-core manually bootstraps AngularJS.

## Routing and navigation

### Single page

Configure a single route to your component:

```javascript
export function configureRoutes($routeProvider: ng.route.IRouteProvider) {
  'ngInject';
  $routeProvider
    .when('/my-plugin', {template: '<my-plugin></my-plugin>'});
}

export const module = angular.module('my-plugin', [])
  .config(configureRoutes)
  ...
  .name;
```

Configure a menu item for your plugin:

```javascript
export function configureNavigation(mainNavService: Nav.MainNavService) {
  'ngInject';
  mainNavService.addItem({
    title: 'My Plugin',
    href: '/my-plugin', // must match configured route
    isValid: () => true, // dynamically show/hide menu item (optional)
    rank: 1 // change item location in the menu (optional)
  });
}

export const module = angular.module('my-plugin', [])
  .run(configureNavigation)
  ...
  .name;
```

### Multiple pages

Configure routes to your components:

```javascript
export function configureRoutes($routeProvider: ng.route.IRouteProvider) {
  'ngInject';
  $routeProvider
    .when('/my-plugin/page1', {template: '<my-plugin-page1></my-plugin-page1>'})
    .when('/my-plugin/page2', {template: '<my-plugin-page2></my-plugin-page2>'})
    .when('/my-plugin/page2/details', {template: '<my-plugin-page2-details></my-plugin-page2-details>'})
    ...
}

export const module = angular.module('my-plugin', [])
  .config(configureRoutes)
  ...
  .name;
```

Configure a menu item for your plugin:

```javascript
export function configureNavigation(mainNavService: Nav.MainNavService) {
  'ngInject';
  mainNavService.addItem({
    title: 'My Plugin',
    basePath: '/my-plugin' // must match base path of configured routes
  });
}

export const module = angular.module('my-plugin', [])
  .run(configureNavigation)
  ...
  .name;
```

## Help documentation

Plugins can register their associated help documentation via the `helpRegistry` service. Just inject it into a run block and add your custom documentation written in Markdown. For example:

```javascript
export function configureHelp(helpRegistry: Help.HelpRegistry) {
  'ngInject';
  helpRegistry.addUserDoc('my-plugin', 'plugins/my-plugin/help.md');
}

export const module = angular.module('my-plugin', [])
  .run(configureHelp)
  ...
  .name;
```

## UI extensions

An extension registration service and a rendering directive are provided to extend the UI. The extension points are named locations in the UI and plugins can register callbacks to produce the HTML that will be added to the DOM.

### Register an extension point callback

In your Hawtio plugin you can register an extension point callback like:

```javascript
  var module = angular.module("MyAwesomePlugin", []);

  module.config(['HawtioExtension', function(HawtioExtension) {
    // Register an extension point callback that returns a string.
    // When a string is returned it will NOT be converted to HTML
    // but will be added as a text node.
    HawtioExtension.add("someExtensionPoint", function(scope){
      return "Some important text!";
    });

    // Register an extension point callback that returns a DOM element
    // When a DOM element is returned it will be appended to the containing
    // <div> of the extension point
    HawtioExtension.add("someExtensionPoint", function(scope){
      var div = document.createElement("div");
      div.className = "awesome";
      div.appendChild(document.createTextNode("I can add stuff!"));

      return div;
    });

    // Register an extension point callback that returns null.
    // Use this if you do not need to append something directly to the extension
    // point but want to make sure some javascript is run when that extension point
    // is rendered.
    HawtioExtension.add("someExtensionPoint", function(scope){
      // some javascript here that does whatever you want
      return null;
    });
  }]);

  hawtioPluginLoader.addModule("MyAwesomePlugin");
```

It is important to note that currently callbacks are rendered in the order they were registered.  In the future we may extend the registration API to include a priority.

### Render an extension point

Any plugin can choose to render all the registered callbacks for an extension point.

#### Using the directive in an angular template (recommended)

```html
<div>
  <h1>Some HTML template for my module</h1>
  <hawtio-extension name="someExtensionPoint"></hawtio-extension>
</div>
```

#### Using the render API

Using the directive method above is recommended in most cases, but does pass down whatever
the current scope is into the callbacks so that they have the same data available to them.
If you want to restrict the data passed down to the callbacks then you can call the service's
render API directly.

```javascript
// Where element is the DOM node that the results of all the callbacks
// will be appended to, and scope is whatever data you want to make available
// to the callbacks.
HawtioExtension.render(extensionPointName, element, scope);
```

## Template caching

Hawtio Core wraps/extends the existing $templateCache and $templateRequest services from AngularJS. If you embed all of your templates into the $templateCache service, then use this functionality to ensure that $templateRequest doesn't try and fetch templates from your server, especially when you've a lot of plugins and templates.

---
_Source: https://npm.io/package/@hawtio/core · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
