Removed old example extensions

This commit is contained in:
Joel Collins 2020-05-15 10:01:10 +01:00
parent ffafd93838
commit 5f7d7be59f
16 changed files with 0 additions and 12240 deletions

View file

@ -1,60 +0,0 @@
from labthings.server.extensions import BaseExtension
from labthings.server.view import View
from labthings.server.decorators import ThingProperty, PropertySchema, use_args
from labthings.server import fields
from labthings.server.find import find_component
from labthings.core.utilities import path_relative_to
from openflexure_microscope.paths import settings_file_path, check_rw
from openflexure_microscope.config import OpenflexureSettingsFile
from openflexure_microscope.api.utilities.gui import build_gui
from flask import abort, url_for
import logging
import os
import psutil
from sys import platform
class CustomElementExtension(BaseExtension):
def __init__(self):
BaseExtension.__init__(
self,
"org.openflexure.customelement",
description="Testing HTML components in an extension",
static_folder=path_relative_to(__file__, "static", "dist"),
)
# Register the on_microscope function to run when the microscope is attached
self.on_component("org.openflexure.microscope", self.on_microscope)
def on_microscope(self, microscope_obj):
"""Function to automatically call when the parent LabThing has a microscope attached."""
logging.debug(f"CustomElementExtension found microscope {microscope_obj}")
customelement_extension_v2 = CustomElementExtension()
def wc_func():
return {
"href": customelement_extension_v2.static_file_url("vue-web-component.min.js"),
"name": "vue-web-component",
}
def gui_func():
return {
"icon": "grid_on",
"title": "Med Scan",
"viewPanel": "stream",
"wc": wc_func(),
}
customelement_extension_v2.add_meta("wc", wc_func)
customelement_extension_v2.add_meta(
"gui", build_gui(gui_func, customelement_extension_v2)
)

View file

@ -1 +0,0 @@
dist/* filter=lfs diff=lfs merge=lfs -text

View file

@ -1,23 +0,0 @@
.DS_Store
node_modules
# local env files
.env.local
.env.*.local
# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
# Override and include dist
!/dist

View file

@ -1,22 +0,0 @@
# Example Web Component using Vue framework
## Structure
### Web component
* `/src/components/VueWebComponent.vue`
### Debug app
* For debugging purposes, the component can be mounted into a demo app
* `/src/App.vue` and `/src/main.js` provide demo app functionality, and do not affect the final built web component
## Building
* Run `npm run build`
## Debugging
* Run `npm run serve` to serve the demo app. This can be used to debug the component. Note, the base URL will be set to it's default value of a localhost microscope server

View file

@ -1,5 +0,0 @@
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
]
}

View file

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:e07e1d811b5182b4e96ab2a29d82db90c8de77d340844cf0acd284388154a671
size 197

View file

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:f03a6823dea074cef32557902c64407cf67899aaa7f6c0d19ff7746bd149fbe0
size 288124

View file

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:155a1dc5d6cbdc787012f83bf82c84b97944ab6b2141f9c566faa375571a3f4a
size 92117

View file

@ -1,20 +0,0 @@
{
"name": "vue-web-component",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "cross-var vue-cli-service build --target wc --inline-vue --name $npm_package_name ./src/components/VueWebComponent.vue"
},
"dependencies": {
"axios": "^0.19.2",
"core-js": "^3.4.4",
"vue": "^2.6.10"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^4.1.0",
"@vue/cli-service": "^4.1.0",
"cross-var": "^1.1.0",
"vue-template-compiler": "^2.6.10"
}
}

View file

@ -1,18 +0,0 @@
<template>
<div id="app">
<VueWebComponent/>
</div>
</template>
<script>
import VueWebComponent from './components/VueWebComponent.vue'
export default {
name: 'app',
components: {
VueWebComponent
}
}
</script>
<style>
</style>

View file

@ -1,72 +0,0 @@
<template>
<div class="my-component-class">
<h1>My Vue Web Component</h1>
<div>Base URL: {{ componentBaseURL }}</div>
<p>Host microscope name: {{ hostDeviceName }}</p>
<p>{{ message }}</p>
<br />
<p>This cheeky little counter has all of its logic contained in a server-side component:</p>
<button type="button" v-on:click="decrement()">-</button>
<span>{{ value }}</span>
<button type="button" v-on:click="increment()">+</button>
</div>
</template>
<script>
import axios from 'axios';
export default {
props: {
'componentBaseURL': {
required: false,
default: "http://localhost:5000/api/v2",
type: String
}
},
data: function() {
return {
value: 0,
message: "",
hostDeviceName: null
};
},
mounted: function() {
console.log(this.componentBaseURL)
if (this.componentBaseURL){
axios
.get(`${this.componentBaseURL}`)
.then(response => {
console.log(response.data)
this.hostDeviceName = response.data.title
})
.catch(function(error) {
console.log("Error reading test json, probabl because of cors or something")
})
}
else {
this.message = "No componentBaseURL given"
}
},
methods: {
decrement: function() {
this.value = this.value -1
},
increment: function() {
this.value = this.value +1
}
}
}
</script>
<style scoped>
.my-component-class {
text-align: center;
}
</style>

View file

@ -1,6 +0,0 @@
import Vue from 'vue';
import App from './App.vue';
new Vue({
render: h => h(App)
}).$mount('#app')

View file

@ -1,4 +0,0 @@
process.env.VUE_APP_NAME = require('./package.json').name
module.exports = {
productionSourceMap: false
};

View file

@ -1,117 +0,0 @@
from labthings.server.view import View
from labthings.server.extensions import BaseExtension
from labthings.server.decorators import ThingAction, ThingProperty
from openflexure_microscope.api.utilities.gui import build_gui
import logging
# Some value that will change over time
# Here, we add 1 to it every time a GET request is made
val_int = 0
def dynamic_form():
global val_int
return {
"id": "test-plugin",
"icon": "pets",
"forms": [
{
"name": "Simple request",
"isCollapsible": False,
"isTask": False,
"selfUpdate": True,
"route": "/do",
"submitLabel": "Do things",
"schema": [
{
"fieldType": "numberInput",
"name": "val_int",
"label": "Number value",
"minValue": 0,
"value": val_int,
},
{
"fieldType": "htmlBlock",
"name": "html_block",
"content": f"<i>Value is: </i><br>{val_int}.", # We dynamically use the val_int variable
},
],
}
],
}
# Alternate form without any dynamic parts
static_form = {
"id": "test-plugin",
"icon": "pets",
"forms": [
{
"name": "Simple request",
"isCollapsible": False,
"isTask": False,
"selfUpdate": True,
"route": "/do",
"submitLabel": "Do things",
"schema": [
{
"fieldType": "numberInput",
"name": "val_int",
"label": "Number value",
"minValue": 0,
"default": 1,
},
{
"fieldType": "htmlBlock",
"name": "html_block",
"content": f"<i>Value is fixed</i>.",
},
],
}
],
}
@ThingProperty
class TestAPIView(View):
def get(self):
global val_int
val_int += 1
return {"val": True}
@ThingAction
class TestDoAPIView(View):
def post(self):
global val_int
val_int += 1
return {"val": True}
# Using the dynamic form
dynamic_test_extension_v2 = BaseExtension("org.openflexure.examples.dynamic-gui")
dynamic_test_extension_v2.add_view(
TestAPIView, "/get", endpoint="dynamic_test_extension_get"
)
dynamic_test_extension_v2.add_view(
TestDoAPIView, "/do", endpoint="dynamic_test_extension_do"
)
dynamic_test_extension_v2.add_meta(
"gui", build_gui(dynamic_form, dynamic_test_extension_v2)
)
# Using the static form
static_test_extension_v2 = BaseExtension("org.openflexure.examples.static-gui")
static_test_extension_v2.add_view(
TestAPIView, "/get", endpoint="static_test_extension_get"
)
static_test_extension_v2.add_view(
TestDoAPIView, "/do", endpoint="static_test_extension_do"
)
static_test_extension_v2.add_meta(
"gui", build_gui(static_form, static_test_extension_v2)
)