A modular developer toolbar and toolset for angularjs apps.
Run yarn start and add the following bookmarklet:
javascript:(function(){const a=window.NgDevTools;if('object'!=typeof a||null===a){const b=document.createElement('SCRIPT');b.type='text/javascript',b.src='http://localhost:9000/bundle.js',b.addEventListener('error',()=>alert('An error occurred loading the bookmarklet'),!1),document.head.appendChild(b)}})();Ensure your settings.js uses the correct angular module name. You'll then be able to load your app, click the bookmarklet and load the toolbar.
Run yarn build and host the /dist folder or the bundle.js file directly. The bookmarklet files in the root of this repo are currently set up to load a file at http://example.com/path/to/bundle.js.
The toolbar is made up of two features, visual modules shown on the toolbar and a CLI-like collection of utilities.
Each module is a class which:
- Takes a
nameparameter in its constructor - Specifies a Vue.js component using the given
nameparameter - Optionally sets a
nameproperty using thenameparameter
To add a module:
- Create a new module file in
src/modules- For the most success, your template should wrap your module in a div with class
toolbar-module
- For the most success, your template should wrap your module in a div with class
- Import the module into src/modules/index.js
- Add the module with a name to the exported object
Modules can render differently dependent on the mode the toolbar is running in. You can access the mode via $root.mode in a Vue template, and you can find the recognised modes in the documentation. Note that dynamic is not a distinct mode, and instead switched between full and compact modes on mouse hover. The mini mode is automatically activated when a modal is shown to ensure action buttons aren't covered
Modules may also render the full width of the screen when in full-mode. Use the css class full-width on your toolbar-module wrapper.
Utilities are static methods of the Util class, exposed via a global object when the toolbar has loaded.
To add a utility, add a static method to the Util class in src/Util.js. Utilities can also be imported by the rest of the toolbar to allow for dependency injection from your angular app. See Util Documentation for more info.
The toolbar exposes a global NgDevTools variable. This provides access to the utilities as listed below via NgDevTools.util and access to the internals of the toolbar via NgDevTools.toolbar.
The toolbar has several modes it can render in:
full- Full information, two lines per module, full widthcompact- Headline information, one line per module, all condenseddynamic- The same ascompactunless hovered, whenfullwill be appliedmini- Brief information, one line per module, few or no words. Automatically activated when modals are shownhidden- Displays nothing at all, useful to capture a screenshot for non-techy use
- Log: Monkey patches
$log.debugand captures all debug messages - UIRouter: Displays the current state rendered, the component rendered by that state and the module it lives in. UIRouter only
- CssDebug: Loads the debucsser helper tool for easier UI debugging
Other app specific modules I've built at work: Access control information, current user information, data entity information
You may access module data exposed by the module class via NgDevTools.toolbar.modules
isPlatform(): Returns a boolean as to whether or not the current page has an angular application with a module that matches theappNameproperty insettings.js$inject(moduleName, exposeToWindow): Returns an angular module from angular's dependency injection system. IfexposeToWindowistrue, the module will be made available globally via thewindowobject. Injections are cached after the first injection.loadAsset(type, url, appentTo): Load a JS file or CSS file from a URL and append it to the DOM.typeisjsorcss,appendTomust be anHTMLElementmodal(title, content, scopeItems, buttons): Spawns a modal via your angular app. Assumes you're using$uibModal.contentis an inline HTML angular template,scopeItemsis an object passed to the template,buttonsis an object that specifies the affirmative and negative footer actions of the modal, defaults to "OK" and "Cancel" respectively
getScope(selector): Get the angular scope of the nearest parent component based on a selector.selectormay be anHTMLElement, jQuery object, CSS selector or angular component name.toJSON(data, space): A safe JSON stringifier that will omit previously seen object references to guard against recursive structures,spacedefaults to2stalk(root, path): Attempts to find where a function is being called from via some hacky monkey patching and stack tracing. Useful if you're unsure what's calling a service method for example.$state: A getter for UIRouter's$statemodule$rootScope: A getter for Angular's$rootScopeobjectpageScope: A getter for the component current being rendered by UIRouter'sui-viewdirectivescopes: A getter that returns an object containing all currently rendered angular components and directives for easy scope access. Production mode must be turned off