Commit 9ef99b14 authored by charitha.p's avatar charitha.p

Deval Plugin

parent a1d67157
### VisualStudioCode template
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace
.idea
# Local History for Visual Studio Code
.history/
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
### Python template
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit tests / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
data/*
logs
/data/keys/
*.stats
.vscode
# Plugin Name
### Author: Devalengineer (charitha.p@knowledgelens.com)
## Project Description:
Fleet management visualize the map with boats and barges
if __name__ == "__main__":
from dotenv import load_dotenv
load_dotenv()
from main import app
app.root_path = None
import logging
import uvicorn
from fastapi import FastAPI
from scripts.config import Service
if __name__ == "__main__":
app = FastAPI()
logging.info(f"App Starting at {Service.HOST}:{Service.PORT}")
uvicorn.run("main:app", host=Service.HOST, port=int(Service.PORT))
from dataclasses import dataclass
from fastapi import FastAPI
from scripts.core.services.widget import router
@dataclass
class FastAPIConfig:
title: str = "Plugin Name"
version: str = "1.0.0"
description: str = "Fleet management visualize the map with boats and barges"
app = FastAPI(**FastAPIConfig().__dict__)
app.include_router(router)
uvicorn~=0.23.1
fastapi[all]>=0.97.0
pydantic==1.10.9
numpy~=1.23.5
python-dotenv==1.0.0
from pydantic import Field, BaseSettings
class _Service(BaseSettings):
HOST: str = Field(default="0.0.0.0", env="service_host")
PORT: int = Field(default=9192, env="service_port")
BUILD_DIR: str = Field(default="scripts/templates")
PROXY: str = Field(default="gateway/plugin/<gen-proxy>")
BACKEND_DIR: str = Field(default=".")
Service = _Service()
# Sys-default
class DefaultAPI:
api_widget = "/widget"
api_load_styles = "/load_styles"
api_load_file = "/load_file"
api_load_configuration = "/load_configuration"
api_preview = "/preview"
from typing import Any, Optional
from pydantic import BaseModel
class DefaultResponse(BaseModel):
status: str = "success"
message: str
data: Optional[Any]
import json
import logging
import os
from fastapi import APIRouter
from scripts.config import Service
from scripts.core.constants.api import DefaultAPI
from scripts.core.schemas.response_models import DefaultResponse
from starlette.responses import FileResponse
router = APIRouter(prefix=DefaultAPI.api_widget)
@router.get(DefaultAPI.load_styles)
async def load_styles():
"""
Default: Loads required endpoints to get filenames in the build
Do not edit this
"""
try:
js_files = [f"{Service.PROXY}/widget/load_file?filename={file}" for file
in
os.listdir(Service.BUILD_DIR)
if os.path.isfile(os.path.join(Service.BUILD_DIR, file)) and file.endswith(".js")]
return DefaultResponse(message="Styles loaded successfully", data=js_files)
except Exception as e:
logging.exception(e)
return DefaultResponse(message="Failed to load file paths", status="failed")
@router.get(DefaultAPI.api_load_file)
def download_resource(filename: str):
"""Default: Request Build Files to redner widget configurations on the frontend
Do not edit this
"""
try:
file_path = os.path.join(Service.BUILD_DIR, filename)
if os.path.isfile(os.path.join(Service.BUILD_DIR, filename)) and filename.endswith(".js"):
return FileResponse(file_path, media_type='application/octet-stream', filename=filename)
else:
return DefaultResponse(message="Failed to load resources")
except Exception as e:
logging.error("Exception " + str(e))
return DefaultResponse(message="File not found")
@router.get(DefaultAPI.api_load_configuration)
async def load_configuration():
"""
Default: Load widget configuration JSON for listing plugins while creating widgets
Do not edit this
"""
try:
with open(f"{Service.BUILD_DIR}/widgetConfig.json", "r") as file:
file_content = json.loads(file.read())
return file_content
except Exception as e:
logging.error(e)
return DefaultResponse(message="Failed to load configurations")
# TODO: Add preview logic. Do not change the API endpoint
@router.get(DefaultAPI.api_preview)
async def preview(request_type: str = "refresh"):
"""
Request Type Options
Preview: Can take in all widget configuration from payload and return Chart Preview Response
Refresh: Will accept widget ID and derive the widget configuration from Widget collection, to then return the
chart response
"""
try:
if request_type not in ["refresh", "preview"]:
return DefaultResponse(message="Invalid Query Parameter")
# Route to Handler for Processing Chart json
return {}
except Exception as e:
logging.error(e)
return DefaultResponse(message="Not found")
{
"cType": "extension",
"chartType": "extension",
"wcType": "extension",
"disabled": false,
"isExtension": true,
"widget_type": [
"static"
],
"label": "Plugin Name",
"description": "Fleet management visualize the map with boats and barges",
"pluginType": "Deval",
"selector": "app-plugin-test",
"settings": {
"chart": {
"display_menu_image": "extension"
},
"config_tabs": {
"general": true,
"chartProp": true,
"tools": true
}
}
}
\ No newline at end of file
{
"cType": "extension",
"chartType": "extension",
"wcType": "extension",
"disabled": false,
"isExtension": true,
"widget_type": [
"static"
],
"label": "Plugin Name",
"description": "Fleet management visualize the map with boats and barges",
"pluginType": "Deval",
"selector": "app-plugin-test",
"settings": {
"chart": {
"display_menu_image": "extension"
},
"config_tabs": {
"general": true,
"chartProp": true,
"tools": true
}
}
}
\ No newline at end of file
{
"plugin_name": "Plugin Name",
"plugin_type": "widget",
"vcs-url": "<git url here>",
"branch": "master",
"environment_variables": {
},
"version": "1.0"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment