Skip to content

Commit d4e3467

Browse files
rueckstiesskangas
authored andcommitted
share schema as json via application menu
1 parent a410092 commit d4e3467

File tree

5 files changed

+58
-4
lines changed

5 files changed

+58
-4
lines changed

src/app.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ var getOrCreateClient = require('scout-client');
1414
var ViewSwitcher = require('ampersand-view-switcher');
1515
var View = require('ampersand-view');
1616
var localLinks = require('local-links');
17+
var debug = require('debug')('scout:app');
18+
19+
// Inter-process communication with main process (Electron window)
20+
var ipc = window.require('ipc');
1721

1822
/**
1923
* The top-level application singleton that brings everything together!
@@ -130,6 +134,13 @@ var Application = View.extend({
130134
event.preventDefault();
131135
this.router.history.navigate(pathname);
132136
}
137+
},
138+
sendMessage: function(msg) {
139+
ipc.send('message', msg);
140+
},
141+
onMessageReceived: function(msg) {
142+
debug('message received from main process:', msg);
143+
this.trigger(msg);
133144
}
134145
});
135146

@@ -161,6 +172,9 @@ app.extend({
161172
};
162173

163174
state.router = new Router();
175+
176+
// set up ipc
177+
ipc.on('message', state.onMessageReceived.bind(this));
164178
},
165179
navigate: state.navigate.bind(state)
166180
});
@@ -180,13 +194,11 @@ Object.defineProperty(app, 'client', {
180194
});
181195
app.init();
182196

183-
// expose app globally for debugging purposes
184-
window.app = app;
185-
186197
function render_app() {
187198
state._onDOMReady();
188199
}
189200

190201
domReady(render_app);
191202

203+
// expose app globally for debugging purposes
192204
window.app = app;

src/electron/menu.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,18 @@ function getTemplate(_window) {
105105
}
106106
]
107107
},
108+
{
109+
label: 'Share',
110+
submenu: [
111+
{
112+
label: 'Share Schema as JSON',
113+
accelerator: 'Alt+Command+S',
114+
click: function() {
115+
_window.webContents.send('message', 'menu-share-schema-json');
116+
}
117+
}
118+
]
119+
},
108120
{
109121
label: 'Window',
110122
submenu: [

src/home/collection.jade

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
.collection-view.clearfix
22
div(data-hook='sampling-message-subview')
3+
div.modal.fade(tabindex='-1', role='dialog', arialabelledby='Share Schema Confirmation', data-hook='share-schema-confirmation')
4+
div.modal-dialog.modal-sm
5+
.modal-content
6+
.modal-header
7+
button.close(type='button', data-dismiss='modal', aria-label='Close')
8+
span(aria-hidden='true')×
9+
h4.modal-title Share Schema
10+
.modal-body
11+
p The schema definition in JSON format has been copied to the clipboard.
12+
.modal-footer
13+
button.btn.btn-default(type='button', data-dismiss='modal') Close
314
header
415
.row
516
.col-md-6

src/home/collection.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ var MongoDBCollection = require('../models/mongodb-collection');
88
var SampledSchema = require('../models/sampled-schema');
99
var app = require('ampersand-app');
1010

11+
var $ = require('jquery');
1112
var debug = require('debug')('scout:home:collection');
1213

14+
require('bootstrap/js/modal');
15+
1316
var MongoDBCollectionView = View.extend({
1417
// modelType: 'Collection',
1518
template: require('./collection.jade'),
@@ -66,8 +69,15 @@ var MongoDBCollectionView = View.extend({
6669
initialize: function() {
6770
this.model = new MongoDBCollection();
6871
app.statusbar.watch(this, this.schema);
72+
debug('app', app);
73+
app.on('menu-share-schema-json', this.shareSchemaRequested.bind(this));
6974
this.listenToAndRun(this.parent, 'change:ns', this.onCollectionChanged.bind(this));
7075
},
76+
shareSchemaRequested: function() {
77+
var clipboard = window.require('clipboard');
78+
clipboard.writeText(JSON.stringify(this.schema.serialize(), null, ' '));
79+
$(this.queryByHook('share-schema-confirmation')).modal('show');
80+
},
7181
onCollectionChanged: function() {
7282
var ns = this.parent.ns;
7383
if (!ns) {

src/models/sampled-schema.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = Schema.extend({
2424
}
2525
}
2626
},
27-
props: {
27+
session: {
2828
is_fetching: {
2929
type: 'boolean',
3030
default: false
@@ -133,5 +133,14 @@ module.exports = Schema.extend({
133133
.pipe(es.map(parse))
134134
.pipe(es.map(addToDocuments))
135135
.pipe(es.wait(onEnd));
136+
},
137+
serialize: function() {
138+
var res = this.getAttributes({
139+
props: true,
140+
derived: true
141+
}, true);
142+
res = _.omit(res, ['name', 'sample_size']);
143+
res.fields = this.fields.serialize();
144+
return res;
136145
}
137146
});

0 commit comments

Comments
 (0)