Skip to content

Commit ce4a06e

Browse files
committed
INT-794 replace html modal with electron dialogs
1 parent d69243c commit ce4a06e

File tree

4 files changed

+63
-29
lines changed

4 files changed

+63
-29
lines changed

src/connect/filereader-view.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var _ = require('lodash');
33
var path = require('path');
44
var remote = window.require('remote');
55
var dialog = remote.require('dialog');
6+
var BrowserWindow = remote.require('browser-window');
67
var format = require('util').format;
78
var bindings = require('ampersand-dom-bindings');
89
var fileReaderTemplate = require('./filereader-default.jade');
@@ -172,7 +173,7 @@ module.exports = InputView.extend({
172173
this.runTests();
173174
},
174175
loadFileButtonClicked: function() {
175-
dialog.showOpenDialog({
176+
dialog.showOpenDialog(BrowserWindow.getFocusedWindow(), {
176177
properties: ['openFile', 'multiSelections']
177178
}, function(filenames) {
178179
this.inputValue = filenames || [];

src/home/collection.jade

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

src/home/collection.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ var RefineBarView = require('../refine-view');
66
var MongoDBCollection = require('../models/mongodb-collection');
77
var SampledSchema = require('../models/sampled-schema');
88
var app = require('ampersand-app');
9-
var $ = require('jquery');
109
var _ = require('lodash');
10+
var remote = window.require('remote');
11+
var dialog = remote.require('dialog');
12+
var BrowserWindow = remote.require('browser-window');
13+
var format = require('util').format;
1114
var debug = require('debug')('scout:home:collection');
1215

13-
require('bootstrap/js/modal');
14-
1516
var MongoDBCollectionView = View.extend({
1617
// modelType: 'Collection',
1718
template: require('./collection.jade'),
@@ -83,7 +84,16 @@ var MongoDBCollectionView = View.extend({
8384
onShareSchema: function() {
8485
var clipboard = window.require('clipboard');
8586
clipboard.writeText(JSON.stringify(this.schema.serialize(), null, ' '));
86-
$(this.queryByHook('share-schema-confirmation')).modal('show');
87+
88+
var detail = format('The schema definition of %s has been copied to your '
89+
+ 'clipboard in JSON format.', this.model._id);
90+
91+
dialog.showMessageBox(BrowserWindow.getFocusedWindow(), {
92+
type: 'info',
93+
message: 'Share Schema',
94+
detail: detail,
95+
buttons: ['OK']
96+
});
8797
},
8898
onCollectionChanged: function() {
8999
var ns = this.parent.ns;

src/minicharts/d3fns/geo.js

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@ var shared = require('./shared');
44
var debug = require('debug')('scout:minicharts:geo');
55
var mapStyle = require('./mapstyle');
66
// var async = require('async');
7-
// var xor = require('xor-it');
87
var app = require('ampersand-app');
98
var format = require('util').format;
10-
9+
var remote = window.require('remote');
10+
var dialog = remote.require('dialog');
11+
var BrowserWindow = remote.require('browser-window');
1112

1213
var SHIFTKEY = 16;
1314
var APIKEY = 'AIzaSyDrhE1qbcnNIh4sK3t7GEcbLRdCNKWjlt0';
14-
// var APIKEY = 'AIzaSyDrhE1qbcnNIh4sZp47GEcbLRdCNKWjlt4'; // wrong one
15-
// function produceKey(text) {
16-
// var key = 'Error: Google map could not be loaded, disabling feature';
17-
// var res = xor(key, text);
18-
// return res;
19-
// }
2015

16+
var FATAL_GOOGLE_ERROR_CODES = [
17+
'InvalidKeyOrUnauthorizedURLMapError',
18+
'NotLoadingAPIFromGoogleMapError',
19+
'TOSViolationMapError',
20+
'UnauthorizedURLForClientIdMapError'
21+
];
2122
// From: http://davidbcalhoun.com/2014/async.parallel-with-a-simple-timeout-node-js/
2223
// async.parallel with optional timeout (options.timeoutMS)
2324
// function parallel(options, tasks, cb) {
@@ -59,10 +60,12 @@ var minicharts_d3fns_geo = function() {
5960

6061
var margin = shared.margin;
6162

62-
function disableMapsFeature() {
63+
function disableMapsFeature(permanent) {
6364
// disable both in feature flag (for this run) and localStorage
6465
app.setFeature('Google Map Minicharts', false);
65-
localStorage.disableGoogleMaps = true;
66+
if (permanent) {
67+
localStorage.disableGoogleMaps = true;
68+
}
6669
delete window.google;
6770
options.view.parent.render();
6871
}
@@ -77,8 +80,38 @@ var minicharts_d3fns_geo = function() {
7780
if (match) {
7881
errorCode = match[1].trim();
7982
}
80-
debug('Error with code "%s" while loading Google Maps. Disabling Geo Querybuilder feature.', errorCode);
81-
disableMapsFeature();
83+
var message;
84+
var detail;
85+
if (FATAL_GOOGLE_ERROR_CODES.indexOf(errorCode) !== -1) {
86+
// maps API key is not valid, we may have had to deactivate it
87+
message = 'The Google Maps API key used in Compass is no longer '
88+
+ 'valid.';
89+
detail = 'Compass will disable the Google Map feature permanently and '
90+
+ 'replace the map with a simplified coordinate chart. Please check '
91+
+ 'for an update to Compass to re-enable this feature.';
92+
disableMapsFeature(true);
93+
debug('Error with code "%s" while loading Google Maps. Disabling Geo '
94+
+ 'Querybuilder feature permanently.', errorCode);
95+
} else {
96+
message = 'There was a problem loading the Google Map.';
97+
detail = 'Compass will disable the Google Map feature temporarily '
98+
+ 'and replace the map with a simplified coordinate chart. Compass '
99+
+ 'will try to load a Google Map again next time you use the '
100+
+ 'application.';
101+
disableMapsFeature(false);
102+
debug('Error with code "%s" while loading Google Maps. Disabling Geo '
103+
+ 'Querybuilder feature temporarily.', errorCode);
104+
}
105+
// show error dialog
106+
dialog.showMessageBox(BrowserWindow.getFocusedWindow(), {
107+
type: 'error',
108+
title: 'Error loading Google Maps',
109+
message: message,
110+
detail: detail,
111+
buttons: ['OK']
112+
});
113+
114+
// @todo thomasr/imlucas: add call to metrics.error here with errror code
82115
};
83116

84117
var script = document.createElement('script');
@@ -216,7 +249,8 @@ var minicharts_d3fns_geo = function() {
216249
.style({
217250
width: (width - margin.left - margin.right) + 'px',
218251
height: (height - margin.top - margin.bottom) + 'px',
219-
padding: margin.top + 'px ' + margin.right + 'px ' + margin.bottom + 'px ' + margin.left + 'px;'
252+
padding: margin.top + 'px ' + margin.right + 'px ' + margin.bottom
253+
+ 'px ' + margin.left + 'px;'
220254
});
221255

222256
if (!window.google) {

0 commit comments

Comments
 (0)