-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
INT-1788: Move help into own ampersand app (#465)
- Loading branch information
Showing
38 changed files
with
253 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>MongoDB Compass</title> | ||
<meta name="viewport" content="initial-scale=1"> | ||
<style> | ||
div#static-sidebar { | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
width: 250px; | ||
height: 100%; | ||
background-color: #4c5259; /* @slate1 */ | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="application"> | ||
<div data-hook="layout-container"> | ||
<div id="static-sidebar" class="sidebar"></div> | ||
</div> | ||
</div> | ||
<script src="help.js" charset="UTF-8" async></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
/* eslint no-console:0 */ | ||
var Environment = require('../environment'); | ||
Environment.init(); | ||
|
||
var path = require('path'); | ||
var resourcePath = path.join(__dirname, '..', '..'); | ||
|
||
var ModuleCache = require('hadron-module-cache'); | ||
ModuleCache.register(resourcePath); | ||
ModuleCache.add(resourcePath); | ||
|
||
var pkg = require('../../package.json'); | ||
var CompileCache = require('hadron-compile-cache'); | ||
CompileCache.setHomeDirectory(resourcePath); | ||
CompileCache.digestMappings = pkg._compileCacheMappings || {}; | ||
|
||
var StyleManager = require('./style-manager'); | ||
StyleManager.writeStyles(); | ||
|
||
/** | ||
* The main entrypoint for the application! | ||
*/ | ||
var electron = require('electron'); | ||
var shell = electron.shell; | ||
var app = require('ampersand-app'); | ||
var APP_VERSION = electron.remote.app.getVersion(); | ||
|
||
var _ = require('lodash'); | ||
var qs = require('qs'); | ||
var ViewSwitcher = require('ampersand-view-switcher'); | ||
var View = require('ampersand-view'); | ||
var localLinks = require('local-links'); | ||
var ipc = require('hadron-ipc'); | ||
var Router = require('./help/router'); | ||
var metrics = require('mongodb-js-metrics')(); | ||
|
||
var addInspectElementMenu = require('debug-menu').install; | ||
|
||
ipc.once('app:launched', function() { | ||
console.log('in app:launched'); | ||
if (process.env.NODE_ENV !== 'production') { | ||
require('debug').enable('mon*,had*'); | ||
require('debug/browser'); | ||
} | ||
}); | ||
|
||
var debug = require('debug')('mongodb-compass:help'); | ||
|
||
var Application = View.extend({ | ||
template: function() { | ||
return [ | ||
'<div id="application">', | ||
' <div data-hook="layout-container"></div>', | ||
'</div>' | ||
].join('\n'); | ||
}, | ||
props: { | ||
version: { | ||
type: 'string', | ||
default: APP_VERSION | ||
} | ||
}, | ||
session: { | ||
/** | ||
* Details of the MongoDB Instance we're currently connected to. | ||
*/ | ||
instance: 'state', | ||
/** | ||
* @see http://learn.humanjavascript.com/react-ampersand/creating-a-router-and-pages | ||
*/ | ||
router: 'object' | ||
}, | ||
events: { | ||
'click a': 'onLinkClick' | ||
}, | ||
onClientReady: function() { | ||
this.startRouter(); | ||
}, | ||
startRouter: function() { | ||
this.router = new Router(); | ||
debug('Listening for page changes from the router...'); | ||
this.listenTo(this.router, 'page', this.onPageChange); | ||
|
||
debug('Starting router...'); | ||
this.router.history.start({ | ||
pushState: false, | ||
root: '/' | ||
}); | ||
}, | ||
/** | ||
* When you want to go to a different page in the app or just save | ||
* state via the URL. | ||
* @param {String} fragment - To update the location bar with. | ||
* @param {Object} [options] - `silent` and `params` | ||
*/ | ||
navigate: function(fragment, options) { | ||
options = _.defaults(options || {}, { | ||
silent: false, | ||
params: null | ||
}); | ||
if (options.params) { | ||
fragment += '?' + qs.stringify(options.params); | ||
} | ||
|
||
var hash = fragment.charAt(0) === '/' ? fragment.slice(1) : fragment; | ||
this.router.history.navigate(hash, { | ||
trigger: !options.silent | ||
}); | ||
}, | ||
/** | ||
* Called a soon as the DOM is ready so we can | ||
* start showing status indicators as | ||
* quickly as possible. | ||
*/ | ||
render: function() { | ||
debug('Rendering app container...'); | ||
|
||
this.el = document.querySelector('#application'); | ||
this.renderWithTemplate(this); | ||
this.pageSwitcher = new ViewSwitcher(this.queryByHook('layout-container'), { | ||
show: function() { | ||
document.scrollTop = 0; | ||
} | ||
}); | ||
|
||
if (process.env.NODE_ENV !== 'production') { | ||
debug('Installing "Inspect Element" context menu'); | ||
addInspectElementMenu(); | ||
} | ||
}, | ||
onPageChange: function(view) { | ||
metrics.track('App', 'viewed', view.screenName); | ||
this.pageSwitcher.set(view); | ||
}, | ||
onLinkClick: function(event) { | ||
// ignore help links, they're handled in `onHelpClicked` | ||
if (event.target.className === 'help') { | ||
return; | ||
} | ||
var pathname = localLinks.getLocalPathname(event); | ||
if (pathname) { | ||
event.preventDefault(); | ||
this.router.history.navigate(pathname); | ||
return; | ||
} else if (event.currentTarget.getAttribute('href') !== '#') { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
shell.openExternal(event.target.href); | ||
} | ||
} | ||
}); | ||
|
||
var state = new Application({}); | ||
|
||
app.extend({ | ||
client: null, | ||
navigate: state.navigate.bind(state), | ||
onDomReady: function() { | ||
state.render(); | ||
// Not serving a part of the app which uses the client, | ||
// so we can just start everything up now. | ||
state.startRouter(); | ||
return; | ||
}, | ||
init: function() { | ||
var self = this; | ||
// signal to main process that app is ready | ||
ipc.call('window:renderer-ready'); | ||
// as soon as dom is ready, render and set up the rest | ||
self.onDomReady(); | ||
} | ||
}); | ||
|
||
Object.defineProperty(app, 'instance', { | ||
get: function() { | ||
return state.instance; | ||
} | ||
}); | ||
|
||
Object.defineProperty(app, 'router', { | ||
get: function() { | ||
return state.router; | ||
} | ||
}); | ||
|
||
Object.defineProperty(app, 'state', { | ||
get: function() { | ||
return state; | ||
} | ||
}); | ||
|
||
app.init(); | ||
|
||
window.app = app; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
src/help/help-entry-collection.js → src/app/help/help-entry-collection.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
var AmpersandRouter = require('ampersand-router'); | ||
var HelpPage = require('./help-page'); | ||
module.exports = AmpersandRouter.extend({ | ||
routes: { | ||
'': 'index', | ||
help: 'index', | ||
'help/:entryId': 'index', | ||
'(*path)': 'catchAll' | ||
}, | ||
index: function(entryId) { | ||
this.help(entryId); | ||
}, | ||
help: function(entryId) { | ||
this.trigger('page', new HelpPage({ entryId: entryId })); | ||
}, | ||
catchAll: function() { | ||
this.redirectTo(''); | ||
} | ||
}); |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters