-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
188 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,73 @@ | ||
import express from 'express'; | ||
import ConfigFile from '../classes/ConfigFile.js'; | ||
import errorLog from '../functions/errorLog.js'; | ||
import WebSocketManager from '../classes/WebSocketManager.js'; | ||
|
||
const r = express.Router(); | ||
|
||
/** | ||
* @swagger | ||
* /preferredPhase: | ||
* post: | ||
* summary: Update the use preferredPhase state | ||
* tags: | ||
* - Configuration | ||
* description: Post data based on InterfaceConfig model. | ||
* requestBody: | ||
* required: true | ||
* content: | ||
* application/json: | ||
* schema: | ||
* type: 'object' | ||
* properties: | ||
* state: | ||
* type: 'string' | ||
* description: The new preferredPhase state. | ||
* example: true | ||
* responses: | ||
* 200: | ||
* description: Success | ||
* content: | ||
* application/json: | ||
* schema: | ||
* type: 'object' | ||
* properties: | ||
* msg: | ||
* type: 'string' | ||
* example: 'success' | ||
* 500: | ||
* description: Error | ||
* content: | ||
* application/json: | ||
* schema: | ||
* type: 'object' | ||
* properties: | ||
* msg: | ||
* type: 'string' | ||
* example: 'Error writing to config file' | ||
*/ | ||
r.post('/preferredPhase', async (req, res) => { | ||
const stateData = req.body.state; | ||
if (stateData !== 0 && stateData !== 1 && stateData !== 2) { | ||
res.status(400).json({ | ||
msg: 'Bad Request: state must be 0, 1, or 2' | ||
}); | ||
return; | ||
} | ||
const configData = ConfigFile.read(); | ||
configData.PreferredPhase = stateData; | ||
const success = ConfigFile.write(configData); | ||
|
||
// It's better to send events after ensuring that data is written successfully. | ||
if (success) { | ||
WebSocketManager.sendEventPreferredPhase(stateData); // Adjusted position | ||
res.status(200).json({ msg: 'success' }); | ||
} else { | ||
errorLog('Error writing preferredPhase state to config file.'); | ||
res.status(500).json({ | ||
msg: 'Error writing to config file' | ||
}); | ||
} | ||
}); | ||
|
||
export default r; |
File renamed without changes.
File renamed without changes.
This file contains 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 @@ | ||
import type ResBase from '../models/ResBase'; | ||
import ApiBase from './ApiBase'; | ||
|
||
export default class extends ApiBase { | ||
static async postEnabled(state: 0 | 1 | 2): Promise<ResBase> { | ||
return this.post<ResBase>('preferredPhase', { state }); | ||
} | ||
} |
This file contains 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 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 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 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 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,47 @@ | ||
<script lang="ts"> | ||
import { newErrorToast, newSuccessToast } from '$lib/api/Utilities/UtilStoreToast'; | ||
import ServiceConfigPreferredPhase from '$lib/api/services/ServiceConfigPreferredPhase'; | ||
import { config } from '$lib/store'; | ||
async function onPreferredPhaseChange() { | ||
await ServiceConfigPreferredPhase.postEnabled($config.PreferredPhase) | ||
.then(() => { | ||
newSuccessToast('Preferred Phase changed: ' + $config.PreferredPhase); | ||
}) | ||
.catch((err) => { | ||
newErrorToast('Preferred Phase change error: ' + err.message); | ||
}); | ||
} | ||
</script> | ||
|
||
<div class="mt-3 p-3 bg-neutral rounded-md"> | ||
<p class="text-2xl underline">PreferredPhase</p> | ||
<div class="flex justify-center"> | ||
<div class="join text-center" on:change={onPreferredPhaseChange}> | ||
<input | ||
type="radio" | ||
bind:group={$config.PreferredPhase} | ||
value={0} | ||
name="options" | ||
aria-label="Auto" | ||
class="join-item btn" | ||
/> | ||
<input | ||
type="radio" | ||
bind:group={$config.PreferredPhase} | ||
value={1} | ||
name="options" | ||
aria-label="Phase 1" | ||
class="join-item btn" | ||
/> | ||
<input | ||
type="radio" | ||
bind:group={$config.PreferredPhase} | ||
value={2} | ||
name="options" | ||
aria-label="Phase 2" | ||
class="join-item btn" | ||
/> | ||
</div> | ||
</div> | ||
</div> |
This file contains 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