GithubHelp home page GithubHelp logo

hawtio / hawtio-core Goto Github PK

View Code? Open in Web Editor NEW
12.0 23.0 18.0 4.11 MB

The core plugin discovery and bootstrapping mechanism for hawtio as an npm package

License: Apache License 2.0

JavaScript 4.40% HTML 6.03% TypeScript 88.50% CSS 0.02% Less 0.95% SCSS 0.10%

hawtio-core's Introduction

Hawtio Core

Test

This package contains the core parts of the Hawtio web console.

hawtio-core features include:

  1. Plugins
  2. Routing and navigation
  3. Help documentation
  4. UI extensions
  5. Template caching

Plugins

Registering inline plugins

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

  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:

{
  "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:

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:

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:

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:

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:

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:

  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)

<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.

// 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.

hawtio-core's People

Contributors

abkieling avatar astefanutti avatar aymenfurter avatar brusdev avatar dependabot[bot] avatar gashcrumb avatar jamesnetherton avatar jwforres avatar kwesterfeld2 avatar morsik avatar oscerd avatar prahaladhchandrahasan avatar tadayosi avatar vinzent avatar

Stargazers

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

Watchers

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

hawtio-core's Issues

Switch code over to typescript

It'd be worth investigating moving the existing code to typescript and start making use of the node.js module resolution stuff in typescript, will probably require implementing #8 first.

A bit of work on this has been done already on this branch

Consider adding tests

Since this module alter's angular's core bootstrapping features, it would be nice if it was covered by tests to ensure stability across updates.

Damper log.info() when using the HawtioCore.UpgradeAdapter

Found a use-case for the HawtioCore.UpgradeAdapter, which isn't really an ng2 use-case. At any rate, when using HawtioCore.UpgradeAdapter, would rather not see:

  ngUpgrade detected, bootstrapping in Angular 1/2 hybrid mode

As first message of the app. Would like this to be log.debug().

The use case here is that we want to bootstrap the app with a dom element other than document.body, to support hot reload with jspm and systemjs hotreload. The hot reload works but requires the reconstruction of the pre-bootstrapped state.

npm package

We should migrate the hawtio-* packages from bower to npm I think, starting here, which will mean then we just have one install command for dependencies etc.

@kahboom FYI

Logger is undefined while loading hawtio-core.js

I'm trying to use just the hawtio-core.js as a bower dependency for loading plugins dynamically. Plugin would be a JS loading an angular module for example.
My project is using require js as well. Hence, in the main.js I call a require on hawtio-core js which depends on angular, angular-sanitize, jquery, js-logger. The JS files are found and loaded including the js-logger.js, but then when hawtio-core.js loads it fails right away on first lines initializing the Logger object. Logger is undefined. Any idea what is going wrong? I went over the js-logger.js and wonder if I need to do anything special to have Logger as a global variable...
Thanks!

"Preferences" Link not working in Safari

When using Safari, the preferences link does not work (After clicking on the link nothing happens). Without having the ability to access the settings page, safari users are not able to change configurations like the auto refresh rate.

Wrap module in an IIFE

As we are using hawtio in the openshift console, I'd like to see the module wrapped in an IIFE just to help ensure some of the work done in the global namespace doesn't clobber anything else.

(function() {
  'use strict';
  // hawtio code here!
})();

Preferences stops working after v3.2.10

After v3.2.10 /hawtio/preferences starts to redirect to /hawtio/Console%20Logs thus the Preferences page cannot be seen.

Initially I thought what I've done at master broke it, but even at v3.2.10 the behaviour reproduces and it doesn't happen at v3.2.9. You can check the issue by running yarn start in this hawtio-core project.

Tab content disappears when active vertical navigation item is clicked

Steps to reproduce

  1. Navigate to a page with tabs
  2. Click on the active vertical navigation item
  3. You should see the tab content disappear

Issue
Angular PatternFly's pf-vertical-navigation component sets the $location.path to the MainNavItem's href attribute, which doesn't have a route.

Possible solution
Replace ngInclude with ngView in MainNavController and change all tabs to work with ngInclude like the Preferences tabs.

Enhance pre-bootstrap tasks so that tasks can have dependencies on other tasks

Currently the options for when a pre-bootstrap task is executed is either at the front or back of the queue. However in some cases you have tasks that need to be executed after other tasks. So we should try and retrofit the ability to provide an object rather than a plain function that can be used to name tasks and determine task dependencies.

yarn audit: 200 vulnerabilities found (97 High)

Is this something to care about ?

#> yarn audit
...
200 vulnerabilities found - Packages audited: 702
Severity: 48 Low | 55 Moderate | 97 High
Done in 3.85s.

running with --groups dependencies only:

#> yarn audit --groups dependencies
...
96 vulnerabilities found - Packages audited: 257
Severity: 13 Low | 53 Moderate | 30 High
Done in 2.56s.

Content disappears

Hello, I have upgraded our container to HawtIO 2.6.0 and I am seeing the same behavior as described in #31.

Navbar not updated when item validity state changes

Navbar items expose the option of providing a validity check function via an isValid property.

Seems this is only respected when the Navbar is first rendered. Thus whenever the result of the isValid function changes, the navbar is not updated to reflect this.

For example, run the hawtio-integration project master branch against a container such as Karaf or EAP. Then deploy a Camel application. Notice that the Camel navbar item never appears, you have to refresh the page.

Bower support dropped

I'm not certain when bower support was dropped, but we still use bower in the openshift web console & can't pull updated versions. Ideally this would have been noted in release notes w/a timetable to move to npm/yarn. Possible to get a bower.json file back?

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.