@jupytergis/jupytergis-qgis 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/plugins.js CHANGED
@@ -1,14 +1,23 @@
1
1
  import { ICollaborativeDrive } from '@jupyter/docprovider';
2
- import { JupyterGISDoc, IJGISExternalCommandRegistryToken } from '@jupytergis/schema';
3
- import { IThemeManager, showErrorMessage } from '@jupyterlab/apputils';
2
+ import { IJGISExternalCommandRegistryToken, JupyterGISDoc } from '@jupytergis/schema';
3
+ import { Dialog, ICommandPalette, IThemeManager, InputDialog, showDialog, showErrorMessage } from '@jupyterlab/apputils';
4
4
  import { IEditorServices } from '@jupyterlab/codeeditor';
5
5
  import { ConsolePanel, IConsoleTracker } from '@jupyterlab/console';
6
+ import { PathExt } from '@jupyterlab/coreutils';
6
7
  import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
8
+ import { Widget } from '@lumino/widgets';
9
+ import { requestAPI } from '@jupytergis/base';
7
10
  import { JupyterGISWidgetFactory } from '@jupytergis/jupytergis-core';
8
11
  import { IJupyterGISDocTracker } from '@jupytergis/schema';
9
- import { requestAPI } from '@jupytergis/base';
10
12
  import { QGSModelFactory, QGZModelFactory } from './modelfactory';
11
- const activate = async (app, tracker, themeManager, drive, externalCommandRegistry, contentFactory, editorServices, rendermime, consoleTracker) => {
13
+ /**
14
+ * The command IDs used by the qgis plugin.
15
+ */
16
+ var CommandIDs;
17
+ (function (CommandIDs) {
18
+ CommandIDs.exportQgis = 'jupytergis:export';
19
+ })(CommandIDs || (CommandIDs = {}));
20
+ const activate = async (app, tracker, themeManager, drive, externalCommandRegistry, contentFactory, editorServices, rendermime, consoleTracker, commandPalette) => {
12
21
  const fcCheck = await requestAPI('jupytergis_qgis/backend-check', {
13
22
  method: 'POST',
14
23
  body: JSON.stringify({})
@@ -33,7 +42,8 @@ const activate = async (app, tracker, themeManager, drive, externalCommandRegist
33
42
  contentFactory,
34
43
  rendermime,
35
44
  mimeTypeService: editorServices.mimeTypeService,
36
- consoleTracker
45
+ consoleTracker,
46
+ drive
37
47
  });
38
48
  const QGZWidgetFactory = new JupyterGISWidgetFactory({
39
49
  name: 'JupyterGIS QGZ Factory',
@@ -48,7 +58,8 @@ const activate = async (app, tracker, themeManager, drive, externalCommandRegist
48
58
  contentFactory,
49
59
  rendermime,
50
60
  mimeTypeService: editorServices.mimeTypeService,
51
- consoleTracker
61
+ consoleTracker,
62
+ drive
52
63
  });
53
64
  // Registering the widget factory
54
65
  app.docRegistry.addWidgetFactory(QGSWidgetFactory);
@@ -90,10 +101,107 @@ const activate = async (app, tracker, themeManager, drive, externalCommandRegist
90
101
  };
91
102
  QGSWidgetFactory.widgetCreated.connect(widgetCreatedCallback);
92
103
  QGZWidgetFactory.widgetCreated.connect(widgetCreatedCallback);
93
- console.log('jupytergis:qgisplugin is activated!');
104
+ /**
105
+ * The command to export the current main area jGIS project to QGIS file ('.qgz').
106
+ *
107
+ * A popup opens to choose a filepath (local from the current jGIS file) if the
108
+ * filepath is not provided in args.
109
+ */
110
+ if (installed) {
111
+ app.commands.addCommand(CommandIDs.exportQgis, {
112
+ label: 'Export To QGZ',
113
+ isEnabled: () => tracker.currentWidget
114
+ ? tracker.currentWidget.context.model.sharedModel.editable
115
+ : false,
116
+ execute: async (args) => {
117
+ var _a, _b;
118
+ const sourceExtension = '.jGIS';
119
+ const extension = '.qgz';
120
+ const model = (_a = tracker.currentWidget) === null || _a === void 0 ? void 0 : _a.context.model.sharedModel;
121
+ if (!model) {
122
+ return;
123
+ }
124
+ const sourcePath = tracker.currentWidget.context.localPath;
125
+ let filepath = (_b = args.filepath) !== null && _b !== void 0 ? _b : null;
126
+ if (!filepath) {
127
+ filepath = (await InputDialog.getText({
128
+ label: 'File name',
129
+ placeholder: PathExt.basename(sourcePath, sourceExtension),
130
+ title: 'Export the project to QGZ file'
131
+ })).value;
132
+ }
133
+ if (filepath === null) {
134
+ // no-op if the dialog has been cancelled.
135
+ return;
136
+ }
137
+ else if (!filepath) {
138
+ // create the filepath if the dialog has been validated empty.
139
+ filepath = `${PathExt.basename(sourcePath, sourceExtension)}${extension}`;
140
+ }
141
+ else if (!filepath.endsWith(extension)) {
142
+ // add the extension to the path if it does not exist.
143
+ filepath = `${filepath}${extension}`;
144
+ }
145
+ let dir = PathExt.dirname(sourcePath);
146
+ if (dir.includes(':')) {
147
+ dir = dir.split(':')[1];
148
+ }
149
+ const absolutePath = PathExt.join(dir, filepath);
150
+ const virtualFile = {
151
+ layers: model.layers,
152
+ sources: model.sources,
153
+ layerTree: model.layerTree.slice().reverse(),
154
+ options: model.options
155
+ };
156
+ // Check if the file exists
157
+ let fileExist = true;
158
+ await drive.get(absolutePath, { content: false }).catch(() => {
159
+ fileExist = false;
160
+ });
161
+ if (fileExist) {
162
+ const overwrite = await showDialog({
163
+ title: 'Export the project to QGZ file',
164
+ body: `The file ${filepath} already exists.\nDo you want to overwrite it ?`
165
+ });
166
+ if (!overwrite.button.accept) {
167
+ return;
168
+ }
169
+ }
170
+ const response = await requestAPI('jupytergis_qgis/export', {
171
+ method: 'POST',
172
+ body: JSON.stringify({
173
+ path: absolutePath,
174
+ virtual_file: virtualFile
175
+ })
176
+ });
177
+ if (!response.exported) {
178
+ showErrorMessage('Export the project to QGZ file', response.logs.errors.length
179
+ ? response.logs.errors.join('\n')
180
+ : 'Unknown error');
181
+ }
182
+ else if (response.logs.warnings.length) {
183
+ const bodyElement = document.createElement('pre');
184
+ bodyElement.textContent = `${filepath} has been exported with warnings\n - ${response.logs.warnings.join('\n - ')}`;
185
+ const body = new Widget({ node: bodyElement });
186
+ await showDialog({
187
+ title: 'Export the project to QGZ file',
188
+ body,
189
+ buttons: [Dialog.okButton()]
190
+ });
191
+ }
192
+ }
193
+ });
194
+ if (commandPalette) {
195
+ commandPalette.addItem({
196
+ command: CommandIDs.exportQgis,
197
+ category: 'JupyterGIS'
198
+ });
199
+ }
200
+ }
201
+ console.log('@jupytergis/jupytergis-qgis:qgisplugin is activated!');
94
202
  };
95
203
  export const qgisplugin = {
96
- id: 'jupytergis:qgisplugin',
204
+ id: '@jupytergis/jupytergis-qgis:qgisplugin',
97
205
  requires: [
98
206
  IJupyterGISDocTracker,
99
207
  IThemeManager,
@@ -104,6 +212,7 @@ export const qgisplugin = {
104
212
  IRenderMimeRegistry,
105
213
  IConsoleTracker
106
214
  ],
215
+ optional: [ICommandPalette],
107
216
  autoStart: true,
108
217
  activate
109
218
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jupytergis/jupytergis-qgis",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "JupyterGIS QGIS extension.",
5
5
  "keywords": [
6
6
  "jupyter",
@@ -15,6 +15,7 @@
15
15
  "author": "JupyterGIS contributors",
16
16
  "files": [
17
17
  "lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}",
18
+ "schema/*.json",
18
19
  "style/**/*.{css,js,eot,gif,html,jpg,json,png,svg,woff2,ttf}"
19
20
  ],
20
21
  "main": "lib/index.js",
@@ -53,9 +54,9 @@
53
54
  },
54
55
  "dependencies": {
55
56
  "@jupyter/docprovider": "^2.0.0",
56
- "@jupytergis/base": "^0.1.3",
57
- "@jupytergis/jupytergis-core": "^0.1.3",
58
- "@jupytergis/schema": "^0.1.3",
57
+ "@jupytergis/base": "^0.1.5",
58
+ "@jupytergis/jupytergis-core": "^0.1.5",
59
+ "@jupytergis/schema": "^0.1.5",
59
60
  "@jupyterlab/application": "^4.0.0",
60
61
  "@jupyterlab/apputils": "^4.0.0",
61
62
  "@jupyterlab/coreutils": "^6.0.0",
@@ -99,6 +100,7 @@
99
100
  }
100
101
  },
101
102
  "extension": true,
103
+ "schemaDir": "schema",
102
104
  "outputDir": "jupytergis_qgis/labextension",
103
105
  "sharedPackages": {
104
106
  "@jupytergis/base": {
@@ -0,0 +1,27 @@
1
+ {
2
+ "title": "Qgis plugin",
3
+ "description": "Schema for the qgis plugin",
4
+ "jupyter.lab.menus": {
5
+ "main": [
6
+ {
7
+ "id": "jp-mainmenu-file",
8
+ "items": [
9
+ {
10
+ "type": "separator",
11
+ "rank": 10
12
+ },
13
+ {
14
+ "command": "jupytergis:export",
15
+ "rank": 10
16
+ },
17
+ {
18
+ "type": "separator",
19
+ "rank": 10
20
+ }
21
+ ]
22
+ }
23
+ ]
24
+ },
25
+ "additionalProperties": false,
26
+ "type": "object"
27
+ }