Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/app/help.html
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>
194 changes: 194 additions & 0 deletions src/app/help.js
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.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var Collection = require('ampersand-rest-collection');
var HelpEntry = require('./help-entry');
var lodashMixin = require('ampersand-collection-lodash-mixin');
var selectableMixin = require('../app/models/selectable-collection-mixin');
var selectableMixin = require('../models/selectable-collection-mixin');
var filterableMixin = require('ampersand-collection-filterable');
var withSync = require('../app/models/with-sync');
var withSync = require('../models/with-sync');
var debug = require('debug')('mongodb-compass:help:help-entry-collection');
var path = require('path');
var _ = require('lodash');
Expand Down
File renamed without changes.
7 changes: 1 addition & 6 deletions src/help/index.js → src/app/help/help-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var debug = require('debug')('mongodb-compass:help');
var HelpSectionCollection = require('./help-section-collection');
var HelpEntryCollection = require('./help-entry-collection');
var HelpEntry = require('./help-entry');
var SidebarView = require('../app/sidebar');
var SidebarView = require('../sidebar');
var ViewSwitcher = require('ampersand-view-switcher');
var app = require('ampersand-app');
var metrics = require('mongodb-js-metrics')();
Expand All @@ -16,8 +16,6 @@ var tagsTemplate = require('./tags.jade');

var entries = new HelpEntryCollection();

var StatusAction = app.appRegistry.getAction('StatusAction');

var HelpPage = View.extend({
template: indexTemplate,
screenName: 'Help',
Expand Down Expand Up @@ -130,12 +128,9 @@ var HelpPage = View.extend({
if (!entry) {
debug('Unknown help entry', entryId);
this.viewSwitcher.clear();
StatusAction.setMessage('Help entry not found.');
return;
}

StatusAction.hide();

if (!entries.select(entry)) {
debug('already selected');
return;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions src/app/help/router.js
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.
2 changes: 1 addition & 1 deletion src/app/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@import "explain-plan/index.less";

@import "../auto-update/index.less";
@import "../help/index.less";
@import "./help/index.less";
@import "metrics/index.less";
@import "./styles/mapbox-gl.css";

Expand Down
8 changes: 0 additions & 8 deletions src/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ module.exports = AmpersandRouter.extend({
schema: 'index',
connect: 'connect',
'schema/:ns': 'schema',
help: 'help',
'help/:entryId': 'help',
'(*path)': 'catchAll'
},
index: function() {
Expand All @@ -18,12 +16,6 @@ module.exports = AmpersandRouter.extend({
ns: ns
}));
},
help: function(entryId) {
var HelpPage = require('../help');
this.trigger('page', new HelpPage({
entryId: entryId
}));
},
catchAll: function() {
this.redirectTo('');
},
Expand Down
18 changes: 10 additions & 8 deletions src/app/sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,16 @@ var SidebarView = View.extend({
this.queryByHook('widget-container'));
}.bind(this));

this.listenToAndRun(app.autoUpdate, 'change:visible', function() {
var el = this.el.querySelector('.sidebar');
if (app.autoUpdate.visible) {
el.classList.add('auto-update-available');
} else {
el.classList.remove('auto-update-available');
}
}.bind(this));
if (app.autoUpdate) {
this.listenToAndRun(app.autoUpdate, 'change:visible', function() {
var el = this.el.querySelector('.sidebar');
if (app.autoUpdate.visible) {
el.classList.add('auto-update-available');
} else {
el.classList.remove('auto-update-available');
}
}.bind(this));
}
},
filterItems: function(searchString) {
var re;
Expand Down
2 changes: 1 addition & 1 deletion src/main/window-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var RESOURCES = path.resolve(__dirname, '../app/');
* created by the `build:pages` gulp task.
*/
var DEFAULT_URL = 'file://' + path.join(RESOURCES, 'index.html#connect');
var HELP_URL = 'file://' + path.join(RESOURCES, 'index.html#help');
var HELP_URL = 'file://' + path.join(RESOURCES, 'help.html#help');

/**
* We want the Connect and Help window to be special
Expand Down