-
Notifications
You must be signed in to change notification settings - Fork 128
Feature/station connection status #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
f52931f
added missing @Column annotation, added custom Directus endpoint
thanaParis 2529c0c
Merge branch 'feature/admin-api' into feature/evse-connection-status
thanaParis d05a6c1
adding total true count to show how many stations are connected at a …
thanaParis 2e8fd42
Merge branch 'rc-1.1.0' into feature/evse-connection-status
thanaParis 30d90e7
setting up new preseeded db for release
thanaParis b9f197d
Forcing addition of dist/index.js for directus extension so that it c…
thanaParis 2ff16ae
directus extension completed, bundled, and added to root
thanaParis 2d7c15d
adding config.js to directus to provide more complex values to enviro…
thanaParis 05daa49
making tsconfig for directus extension match the rest of the repository.
thanaParis c1c2d5e
Merge branch 'rc-1.1.0' into feature/station-connection-status
thanaParis 28c4d44
moving files in order to rename top level folder to 'DirectusExtensions'
thanaParis e340c80
Merge branch 'rc-1.1.0' into feature/station-connection-status
thanaParis 6eae968
fixing directus extension bundle to be built inside dockerfile
thanaParis f271246
fixing issue with building directus bundle in dockerfile, added healt…
thanaParis 265b229
Update DirectusExtensions/charging-stations-bundle/src/display-true-c…
thanaParis c9ae76f
merged paths
thanaParis 1f4c7a7
Merge branch 'feature/station-connection-status' of https://github.co…
thanaParis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| { | ||
| "name": "directus-extension-charging-stations-bundle", | ||
| "description": "Directus extension bundle for CitrineOS to support charging stations", | ||
| "icon": "extension", | ||
| "version": "1.0.0", | ||
| "keywords": [ | ||
| "directus", | ||
| "directus-extension", | ||
| "directus-extension-bundle" | ||
| ], | ||
| "type": "module", | ||
| "files": [ | ||
| "dist" | ||
| ], | ||
| "directus:extension": { | ||
| "type": "bundle", | ||
| "path": { | ||
| "app": "dist/app.js", | ||
| "api": "dist/api.js" | ||
| }, | ||
| "entries": [ | ||
| { | ||
| "type": "display", | ||
| "name": "Present or True Count", | ||
| "source": "src/display-true-count/index.ts" | ||
| }, | ||
| { | ||
| "type": "endpoint", | ||
| "name": "Charging Stations endpoints", | ||
| "source": "src/endpoints-charging-stations/index.ts" | ||
| }, | ||
| { | ||
| "type": "hook", | ||
| "name": "On Create Charging Station", | ||
| "source": "src/hook-on-create-charging-station/index.ts" | ||
| } | ||
| ], | ||
| "host": "^10.10.0" | ||
| }, | ||
| "scripts": { | ||
| "build": "npx directus-extension build", | ||
| "dev": "npx directus-extension build -w --no-minify", | ||
| "link": "npx directus-extension link", | ||
| "add": "npx directus-extension add" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/node": "^20.11.30", | ||
| "typescript": "^5.4.3" | ||
| }, | ||
| "dependencies": { | ||
| "@directus/extensions-sdk": "^11.0.1", | ||
| "@directus/types": "^11.0.7" | ||
| } | ||
| } |
55 changes: 55 additions & 0 deletions
55
DirectusExtensions/charging-stations-bundle/src/display-true-count/display.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| <template> | ||
| <span>{{ calculatedValue }}{{ totalPrefix }}{{ total }}{{ suffix }}</span> | ||
| </template> | ||
|
|
||
| <script lang="ts"> | ||
| // Copyright Contributors to the CitrineOS Project | ||
| // | ||
| // SPDX-License-Identifier: Apache 2.0 | ||
|
|
||
| import { defineComponent, ref } from 'vue'; | ||
|
|
||
| export default defineComponent({ | ||
| props: { | ||
| value: { | ||
| type: Array<object | string>, | ||
| default: null, | ||
| }, | ||
| column: { | ||
| type: String, | ||
| default: null, | ||
| }, | ||
| showTotal: { | ||
| type: Boolean, | ||
| default: false, | ||
| }, | ||
| totalPrefix: { | ||
| type: String, | ||
| default: null, | ||
| }, | ||
| suffix: { | ||
| type: String, | ||
| default: null, | ||
| }, | ||
| }, | ||
| setup(props) { | ||
| const calculatedValue = ref(0); | ||
| const total = props.showTotal ? props.value.length : null; | ||
|
|
||
| props.value.forEach(item => { | ||
| const columns = props.column.split('.'); | ||
|
|
||
| columns.forEach(col => { | ||
| item = item[col]; | ||
| }); | ||
|
|
||
| if (item && item !== 'false') { | ||
| calculatedValue.value += 1; | ||
| } | ||
| }); | ||
|
|
||
|
|
||
| return { calculatedValue, total }; | ||
| }, | ||
| }); | ||
| </script> | ||
116 changes: 116 additions & 0 deletions
116
DirectusExtensions/charging-stations-bundle/src/display-true-count/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| // Copyright Contributors to the CitrineOS Project | ||
| // | ||
| // SPDX-License-Identifier: Apache 2.0 | ||
|
|
||
| import { defineDisplay, useStores } from '@directus/extensions-sdk'; | ||
| import DisplayComponent from './display.vue'; | ||
| import { DeepPartial, Field, FieldMeta } from '@directus/types'; | ||
|
|
||
| export default defineDisplay({ | ||
| id: 'directus-display-true-count', | ||
| name: 'Count Present or True', | ||
| icon: '123', | ||
| description: 'Count present or true rows in a column', | ||
| component: DisplayComponent, | ||
| options: ({ editing, relations }) => { | ||
| const relatedCollection = | ||
| relations.o2m?.meta?.junction_field != null ? relations.m2o?.related_collection : relations.o2m?.collection; | ||
|
|
||
| const junction_table = relations.o2m?.meta?.junction_field != null ? relations.o2m?.collection : null; | ||
| const { useFieldsStore } = useStores(); | ||
| const fieldsStore = useFieldsStore(); | ||
|
|
||
| let fieldSelection: DeepPartial<FieldMeta>; | ||
| if (editing === '+') { | ||
| fieldSelection = { | ||
| interface: 'presentation-notice', | ||
| options: { | ||
| text: 'Please complete the field before attempting to configure the display.', | ||
| }, | ||
| width: 'full', | ||
| }; | ||
| } else { | ||
| const fields: Field[] = fieldsStore.getFieldsForCollection(relatedCollection); | ||
| const field_choices: object[] = []; | ||
|
|
||
| // console.log("fields", fields); | ||
|
|
||
| fields.forEach((field) => { | ||
| // console.log(field); | ||
| field_choices.push({ | ||
| text: field.field, | ||
| value: junction_table ? `${relations.o2m?.meta?.junction_field}.${field.field}` : field.field, | ||
| }); | ||
| }); | ||
|
|
||
| fieldSelection = { | ||
| interface: 'select-dropdown', | ||
| options: { | ||
| choices: field_choices, | ||
| }, | ||
| width: 'full', | ||
| }; | ||
| } | ||
|
|
||
| return [ | ||
| { | ||
| field: 'column', | ||
| name: 'Choose a column', | ||
| meta: fieldSelection, | ||
| }, | ||
| { | ||
| field: 'showTotal', | ||
| type: 'boolean', | ||
| name: 'Show Total', | ||
| meta: { | ||
| interface: 'boolean', | ||
| options: { | ||
| label: 'Show Total', | ||
| }, | ||
| width: 'half', | ||
| }, | ||
| }, | ||
| { | ||
| field: 'totalPrefix', | ||
| type: 'string', | ||
| name: 'Total Prefix', | ||
| meta: { | ||
| interface: 'input', | ||
| options: { | ||
| font: 'monospace', | ||
| }, | ||
| width: 'half', | ||
| hidden: true, | ||
| conditions: [ | ||
| { | ||
| name: 'showTotalTrue', | ||
| rule: { | ||
| "showTotal": { | ||
| "_eq": true | ||
| } | ||
| }, | ||
| hidden: false | ||
| } | ||
| ] | ||
| }, | ||
| }, | ||
| { | ||
| field: 'suffix', | ||
| type: 'string', | ||
| name: 'Suffix', | ||
| meta: { | ||
| interface: 'input', | ||
| options: { | ||
| font: 'monospace', | ||
| }, | ||
| width: 'half', | ||
| }, | ||
| }, | ||
| ]; | ||
| }, | ||
| types: ['alias', 'string', 'uuid', 'integer', 'bigInteger', 'json'], | ||
| localTypes: ['m2m', 'm2o', 'o2m', 'translations', 'm2a', 'file', 'files'], | ||
| fields: (options) => { | ||
| return [options.column]; | ||
| }, | ||
| }); |
5 changes: 5 additions & 0 deletions
5
DirectusExtensions/charging-stations-bundle/src/display-true-count/shims.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| declare module '*.vue' { | ||
| import { DefineComponent } from 'vue'; | ||
| const component: DefineComponent<{}, {}, any>; | ||
| export default component; | ||
| } |
38 changes: 38 additions & 0 deletions
38
DirectusExtensions/charging-stations-bundle/src/endpoints-charging-stations/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // Copyright Contributors to the CitrineOS Project | ||
| // | ||
| // SPDX-License-Identifier: Apache 2.0 | ||
|
|
||
| import { defineEndpoint } from '@directus/extensions-sdk'; | ||
|
|
||
| export default defineEndpoint({ | ||
| id: 'charging-stations', | ||
| handler: (router, { database }) => { | ||
| router.post('/update-station-status', async (req, res) => { | ||
|
thanaParis marked this conversation as resolved.
|
||
| try { | ||
| console.log("update-station-status request received: " + JSON.stringify(req.body)); | ||
| const { stationId, event } = req.body; | ||
| let isOnline = false; | ||
|
|
||
| // Determine the status based on the event type | ||
| if (event === 'connected') { | ||
| isOnline = true; | ||
| } else if (event === 'closed') { | ||
| isOnline = false; | ||
| } else { | ||
| // If the event type is neither 'connected' nor 'closed', return an error | ||
| return res.status(400).json({ message: 'Invalid event type, expecting only "connected" or "closed"' }); | ||
| } | ||
|
|
||
| // Update the `isOnline` field in the `ChargingStation` collection for the specified stationId | ||
| await database('ChargingStations') | ||
| .where({ id: stationId }) | ||
| .update({ isOnline }); | ||
|
|
||
| return res.status(200).json({ message: 'ChargingStation status updated successfully' }); | ||
| } catch (error) { | ||
| console.error('Error updating ChargingStation status:', error); | ||
| return res.status(500).json({ message: 'Internal server error' }); | ||
| } | ||
| }); | ||
| } | ||
| }); | ||
35 changes: 35 additions & 0 deletions
35
DirectusExtensions/charging-stations-bundle/src/hook-on-create-charging-station/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // Copyright Contributors to the CitrineOS Project | ||
| // | ||
| // SPDX-License-Identifier: Apache 2.0 | ||
|
|
||
| import { defineHook } from '@directus/extensions-sdk'; | ||
|
|
||
| export default defineHook(({ action }, { env }) => { | ||
|
|
||
| action('ChargingStations.items.create', (input) => { | ||
| console.log("Subscribing " + input.key + " to connect and close events"); | ||
|
|
||
| const stationId = input.key; | ||
| const subscriptionUrl = `${env.CITRINEOS_URL}${env.CITRINEOS_SUBSCRIPTION_API_PATH}`; | ||
| const updateStationStatusUrl = `${env.DIRECTUS_URL}${env.DIRECTUS_CHARGING_STATION_UPDATE_STATUS_PATH}`; | ||
|
thanaParis marked this conversation as resolved.
|
||
| const requestBody = { | ||
| stationId: stationId, | ||
| onConnect: true, | ||
| onClose: true, | ||
| url: updateStationStatusUrl | ||
| } | ||
|
|
||
| console.log("Subscribing to " + subscriptionUrl + " with request body " + JSON.stringify(requestBody)); | ||
| fetch(subscriptionUrl, { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/json' | ||
| }, | ||
| body: JSON.stringify(requestBody) | ||
| }).then((response) => { | ||
| console.log('Response: ', response); | ||
| }).catch((error) => { | ||
| console.log('Error: ', error); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "extends": "../../tsconfig.build.json", | ||
| "include": [ | ||
| "src/**/*.ts", | ||
| "src/**/*.json" | ||
| ], | ||
| "compilerOptions": { | ||
| "outDir": "./dist/", | ||
| "composite": true, | ||
| "rootDir": "./src" | ||
| } | ||
| } |
Binary file removed
BIN
-18.9 KB
Server/data/directus/uploads/2937fa22-293e-4aae-805e-ad83c7843a6e.png
Binary file not shown.
Binary file removed
BIN
-3.95 KB
...7fa22-293e-4aae-805e-ad83c7843a6e__589fd140dc03b11360453048b8c68765d61556b2.png
Binary file not shown.
Binary file removed
BIN
-18.9 KB
Server/data/directus/uploads/2d6b4619-1cd0-48f6-99ea-bdc292688342.png
Binary file not shown.
Binary file removed
BIN
-14.1 KB
...b4619-1cd0-48f6-99ea-bdc292688342__4f7f2791732f0b8f33c44abe69d6e5b615ea3f17.png
Binary file not shown.
Binary file removed
BIN
-4.03 KB
...b4619-1cd0-48f6-99ea-bdc292688342__589fd140dc03b11360453048b8c68765d61556b2.png
Binary file not shown.
Binary file removed
BIN
-18.9 KB
Server/data/directus/uploads/9fbe60db-0d6b-452f-9100-3c148e025fd1.png
Binary file not shown.
Binary file removed
BIN
-3.95 KB
...e60db-0d6b-452f-9100-3c148e025fd1__589fd140dc03b11360453048b8c68765d61556b2.png
Binary file not shown.
Binary file removed
BIN
-18.9 KB
Server/data/directus/uploads/c54bf973-4c89-4298-8e87-6c69fbd4fd96.png
Binary file not shown.
Binary file removed
BIN
-3.95 KB
...bf973-4c89-4298-8e87-6c69fbd4fd96__589fd140dc03b11360453048b8c68765d61556b2.png
Binary file not shown.
Binary file removed
BIN
-18.9 KB
Server/data/directus/uploads/e79f2dd1-73b3-42eb-9c85-e0aae4ee1d68.png
Binary file not shown.
Binary file removed
BIN
-3.95 KB
...f2dd1-73b3-42eb-9c85-e0aae4ee1d68__589fd140dc03b11360453048b8c68765d61556b2.png
Binary file not shown.
Binary file removed
BIN
-15 KB
Server/data/directus/uploads/fe3776b9-c57e-4347-9b36-43c3f37c39a0.png
Binary file not shown.
Binary file removed
BIN
-1.63 KB
...776b9-c57e-4347-9b36-43c3f37c39a0__589fd140dc03b11360453048b8c68765d61556b2.png
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // Copyright Contributors to the CitrineOS Project | ||
| // | ||
| // SPDX-License-Identifier: Apache 2.0 | ||
|
|
||
| module.exports = function (env) { | ||
| const config = { | ||
| // API Paths | ||
| CITRINEOS_SUBSCRIPTION_API_PATH: '/data/ocpprouter/subscription', | ||
| DIRECTUS_CHARGING_STATION_UPDATE_STATUS_PATH: '/charging-stations/update-station-status', | ||
| // Environment-specific urls | ||
| CITRINEOS_URL: "http://citrine:8080", | ||
| DIRECTUS_URL: "http://directus:8055" | ||
| } | ||
|
|
||
| return config; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| FROM directus/directus:10.10.5 | ||
| USER root | ||
| COPY tsconfig.build.json /directus | ||
| COPY DirectusExtensions/charging-stations-bundle/tsconfig.json /directus/extensions/directus-extension-charging-stations-bundle/tsconfig.json | ||
| COPY DirectusExtensions/charging-stations-bundle/package.json /directus/extensions/directus-extension-charging-stations-bundle/package.json | ||
| COPY DirectusExtensions/charging-stations-bundle/src /directus/extensions/directus-extension-charging-stations-bundle/src | ||
| RUN npm install --prefix /directus/extensions/directus-extension-charging-stations-bundle && npm run build --prefix /directus/extensions/directus-extension-charging-stations-bundle | ||
| USER node |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.