Skip to content

Commit 4b98a94

Browse files
authored
Merge pull request #12 from terrestris/feat/list-of-applications
Feature: load list of applications of SHOGun instance via GraphQL
2 parents f3bc085 + d4e6b68 commit 4b98a94

23 files changed

Lines changed: 514 additions & 169 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ __pycache__/
33
*.py[cod]
44
*$py.class
55
docker/qgis_plugins/*
6+
plugin_code/shogun_qgis_venv/
67

78
# C extensions
89
*.so

Dockerfile

Lines changed: 0 additions & 23 deletions
This file was deleted.

docker/docker-compose-dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
services:
22
qgis:
33
image: qgis/qgis:3.44
4-
command: ["/bin/bash", "-c", "pip install debugpy; qgis /root/shogun_qgis_konfigurator.qgs"]
4+
command: ["/bin/bash", "-c", "qgis /root/shogun_qgis_konfigurator.qgs"]
55
environment:
66
DISPLAY: "unix${DISPLAY}"
77
RUN_IN_DOCKER: "1"

plugin_code/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
This script initializes the plugin, making it known to QGIS.
2323
"""
2424

25+
from qgis.core import QgsMessageLog
26+
2527

2628
# noinspection PyPep8Naming
2729
def classFactory(iface): # pylint: disable=invalid-name
@@ -31,5 +33,10 @@ def classFactory(iface): # pylint: disable=invalid-name
3133
:type iface: QgsInterface
3234
"""
3335
#
36+
import os
37+
38+
project_path = os.path.dirname(__file__)
39+
QgsMessageLog.logMessage(f"Project path: {project_path}", "QgisShogunEditor")
40+
3441
from .qgis_shogun_editor import QgisShogunEditor
3542
return QgisShogunEditor(iface)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class GraphQLException(Exception):
2+
pass

plugin_code/exception/__init__.py

Whitespace-only changes.

plugin_code/metadata.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ tags=python
2727

2828
homepage=http://homepage
2929
category=Plugins
30-
icon=icon.png
30+
icon=shogun_logo.png
3131
# experimental flag
3232
experimental=True
3333

@@ -37,7 +37,7 @@ deprecated=False
3737
# Since QGIS 3.8, a comma separated list of plugins to be installed
3838
# (or upgraded) can be specified.
3939
# Check the documentation for more information.
40-
# plugin_dependencies=
40+
plugin_dependencies=qpip
4141

4242
Category of the plugin: Raster, Vector, Database or Web
4343
# category=

plugin_code/models/Application.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from dataclasses import dataclass
2+
from typing import Any, Dict, Optional
3+
4+
from ..models.BaseEntity import BaseEntity
5+
6+
7+
@dataclass
8+
class Application(BaseEntity):
9+
name: Optional[str] = None
10+
state_only: Optional[bool] = None
11+
client_config: Optional[Dict[str, Any]] = None
12+
layer_tree: Optional[Dict[str, Any]] = None
13+
layer_config: Optional[Dict[str, Any]] = None
14+
tool_config: Optional[Dict[str, Any]] = None
15+
16+
@classmethod
17+
def from_dict(cls, data: Dict[str, Any]) -> 'Application':
18+
base = super().from_dict(data)
19+
return cls(
20+
_id=base._id,
21+
created=base.created,
22+
modified=base.modified,
23+
name=data.get('name'),
24+
state_only=data.get('stateOnly'),
25+
client_config=data.get('clientConfig'),
26+
layer_tree=data.get('layerTree'),
27+
layer_config=data.get('layerConfig'),
28+
tool_config=data.get('toolConfig')
29+
)

plugin_code/models/BaseEntity.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from dataclasses import dataclass
2+
from datetime import datetime
3+
from enum import Enum
4+
from typing import Any, Dict, Optional
5+
6+
7+
class LayerType(Enum):
8+
TILE_WMS = "TileWMS"
9+
VECTOR_TILE = "VectorTile"
10+
WFS = "WFS"
11+
WMS = "WMS"
12+
WMTS = "WMTS"
13+
XYZ = "XYZ"
14+
15+
16+
class RevisionType(Enum):
17+
INSERT = "INSERT"
18+
UPDATE = "UPDATE"
19+
DELETE = "DELETE"
20+
21+
22+
@dataclass
23+
class BaseEntity:
24+
_id: Optional[int] = None
25+
created: Optional[datetime] = None
26+
modified: Optional[datetime] = None
27+
28+
@classmethod
29+
def from_dict(cls, data: Dict[str, Any]) -> 'BaseEntity':
30+
return cls(
31+
_id=data.get('id'),
32+
created=cls._parse_datetime(data.get('created')),
33+
modified=cls._parse_datetime(data.get('modified'))
34+
)
35+
36+
@staticmethod
37+
def _parse_datetime(date_str: Optional[str]) -> Optional[datetime]:
38+
if not date_str:
39+
return None
40+
try:
41+
return datetime.fromisoformat(date_str.replace('Z', '+00:00'))
42+
except (ValueError, AttributeError):
43+
return None

plugin_code/models/Layer.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from dataclasses import dataclass
2+
from typing import Any, Dict, Optional
3+
4+
from .BaseEntity import BaseEntity
5+
6+
7+
@dataclass
8+
class Layer(BaseEntity):
9+
name: Optional[str] = None
10+
client_config: Optional[Dict[str, Any]] = None
11+
source_config: Optional[Dict[str, Any]] = None
12+
features: Optional[Dict[str, Any]] = None
13+
layerType: Optional[str] = None
14+
15+
@classmethod
16+
def from_dict(cls, data: Dict[str, Any]) -> 'Layer':
17+
base = super().from_dict(data)
18+
return cls(
19+
_id=base._id,
20+
created=base.created,
21+
modified=base.modified,
22+
name=data.get('name'),
23+
client_config=data.get('clientConfig'),
24+
source_config=data.get('sourceConfig'),
25+
features=data.get('features'),
26+
layerType=data.get('type')
27+
)

0 commit comments

Comments
 (0)