@jupytergis/jupytergis-qgis 0.1.2 → 0.1.4

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
2
  import { JupyterGISDoc, IJGISExternalCommandRegistryToken } from '@jupytergis/schema';
3
- import { IThemeManager, showErrorMessage } from '@jupyterlab/apputils';
3
+ import { Dialog, ICommandPalette, InputDialog, IThemeManager, showDialog, showErrorMessage } from '@jupyterlab/apputils';
4
4
  import { IEditorServices } from '@jupyterlab/codeeditor';
5
+ import { PathExt } from '@jupyterlab/coreutils';
5
6
  import { ConsolePanel, IConsoleTracker } from '@jupyterlab/console';
6
7
  import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
8
+ import { Widget } from '@lumino/widgets';
7
9
  import { JupyterGISWidgetFactory } from '@jupytergis/jupytergis-core';
8
10
  import { IJupyterGISDocTracker } from '@jupytergis/schema';
9
11
  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({})
@@ -90,10 +99,107 @@ const activate = async (app, tracker, themeManager, drive, externalCommandRegist
90
99
  };
91
100
  QGSWidgetFactory.widgetCreated.connect(widgetCreatedCallback);
92
101
  QGZWidgetFactory.widgetCreated.connect(widgetCreatedCallback);
93
- console.log('jupytergis:qgisplugin is activated!');
102
+ /**
103
+ * The command to export the current main area jGIS project to QGIS file ('.qgz').
104
+ *
105
+ * A popup opens to choose a filepath (local from the current jGIS file) if the
106
+ * filepath is not provided in args.
107
+ */
108
+ if (installed) {
109
+ app.commands.addCommand(CommandIDs.exportQgis, {
110
+ label: 'Export To QGZ',
111
+ isEnabled: () => tracker.currentWidget
112
+ ? tracker.currentWidget.context.model.sharedModel.editable
113
+ : false,
114
+ execute: async (args) => {
115
+ var _a, _b;
116
+ const sourceExtension = '.jGIS';
117
+ const extension = '.qgz';
118
+ const model = (_a = tracker.currentWidget) === null || _a === void 0 ? void 0 : _a.context.model.sharedModel;
119
+ if (!model) {
120
+ return;
121
+ }
122
+ const sourcePath = tracker.currentWidget.context.localPath;
123
+ let filepath = (_b = args.filepath) !== null && _b !== void 0 ? _b : null;
124
+ if (!filepath) {
125
+ filepath = (await InputDialog.getText({
126
+ label: 'File name',
127
+ placeholder: PathExt.basename(sourcePath, sourceExtension),
128
+ title: 'Export the project to QGZ file'
129
+ })).value;
130
+ }
131
+ if (filepath === null) {
132
+ // no-op if the dialog has been cancelled.
133
+ return;
134
+ }
135
+ else if (!filepath) {
136
+ // create the filepath if the dialog has been validated empty.
137
+ filepath = `${PathExt.basename(sourcePath, sourceExtension)}${extension}`;
138
+ }
139
+ else if (!filepath.endsWith(extension)) {
140
+ // add the extension to the path if it does not exist.
141
+ filepath = `${filepath}${extension}`;
142
+ }
143
+ let dir = PathExt.dirname(sourcePath);
144
+ if (dir.includes(':')) {
145
+ dir = dir.split(':')[1];
146
+ }
147
+ const absolutePath = PathExt.join(dir, filepath);
148
+ const virtualFile = {
149
+ layers: model.layers,
150
+ sources: model.sources,
151
+ layerTree: model.layerTree.slice().reverse(),
152
+ options: model.options
153
+ };
154
+ // Check if the file exists
155
+ let fileExist = true;
156
+ await drive.get(absolutePath, { content: false }).catch(() => {
157
+ fileExist = false;
158
+ });
159
+ if (fileExist) {
160
+ const overwrite = await showDialog({
161
+ title: 'Export the project to QGZ file',
162
+ body: `The file ${filepath} already exists.\nDo you want to overwrite it ?`
163
+ });
164
+ if (!overwrite.button.accept) {
165
+ return;
166
+ }
167
+ }
168
+ const response = await requestAPI('jupytergis_qgis/export', {
169
+ method: 'POST',
170
+ body: JSON.stringify({
171
+ path: absolutePath,
172
+ virtual_file: virtualFile
173
+ })
174
+ });
175
+ if (!response.exported) {
176
+ showErrorMessage('Export the project to QGZ file', response.logs.errors.length
177
+ ? response.logs.errors.join('\n')
178
+ : 'Unknown error');
179
+ }
180
+ else if (response.logs.warnings.length) {
181
+ const bodyElement = document.createElement('pre');
182
+ bodyElement.textContent = `${filepath} has been exported with warnings\n - ${response.logs.warnings.join('\n - ')}`;
183
+ const body = new Widget({ node: bodyElement });
184
+ await showDialog({
185
+ title: 'Export the project to QGZ file',
186
+ body,
187
+ buttons: [Dialog.okButton()]
188
+ });
189
+ }
190
+ }
191
+ });
192
+ if (commandPalette) {
193
+ commandPalette.addItem({
194
+ command: CommandIDs.exportQgis,
195
+ category: 'JupyterGIS'
196
+ });
197
+ }
198
+ }
199
+ console.log('@jupytergis/jupytergis-qgis:qgisplugin is activated!');
94
200
  };
95
201
  export const qgisplugin = {
96
- id: 'jupytergis:qgisplugin',
202
+ id: '@jupytergis/jupytergis-qgis:qgisplugin',
97
203
  requires: [
98
204
  IJupyterGISDocTracker,
99
205
  IThemeManager,
@@ -104,6 +210,7 @@ export const qgisplugin = {
104
210
  IRenderMimeRegistry,
105
211
  IConsoleTracker
106
212
  ],
213
+ optional: [ICommandPalette],
107
214
  autoStart: true,
108
215
  activate
109
216
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jupytergis/jupytergis-qgis",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
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.2",
57
- "@jupytergis/jupytergis-core": "^0.1.2",
58
- "@jupytergis/schema": "^0.1.2",
57
+ "@jupytergis/base": "^0.1.4",
58
+ "@jupytergis/jupytergis-core": "^0.1.4",
59
+ "@jupytergis/schema": "^0.1.4",
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
+ }