diff --git a/client/src/services/analytics.service.ts b/client/src/services/analytics.service.ts index 721a78d..9aec2d4 100644 --- a/client/src/services/analytics.service.ts +++ b/client/src/services/analytics.service.ts @@ -48,6 +48,11 @@ export async function getConfig(): Promise<[AnalyticUnitType, AnlyticUnitConfig] return [analyticUnitType, analyticUnitConfig]; } +export async function patchConfig(patchObj: any) { + const uri = ANALYTICS_API_URL + `config`; + await axios.patch(uri, patchObj); +} + export function getStatusGenerator(): AsyncIterableIterator { return getGenerator(100, getStatus); } diff --git a/client/src/store/index.ts b/client/src/store/index.ts index 78bde02..4a9d265 100644 --- a/client/src/store/index.ts +++ b/client/src/store/index.ts @@ -1,14 +1,17 @@ import { auth } from "./auth.module"; import { createStore } from 'vuex' -import { getConfig, getStatusGenerator } from "@/services/analytics.service"; +import { getConfig, getStatusGenerator, patchConfig } from "@/services/analytics.service"; import { AnlyticUnitConfig, AnalyticUnitType } from '@/types/analytic_units' // import { notify } from "@kyvg/vue3-notification"; const SET_ANALYTICS_STATUS = 'SET_ANALYTICS_STATUS'; const SET_DETECTOR_CONFIG = 'SET_DETECTOR_CONFIG'; +// const PATCH_CONFIG = 'PATCH_CONFIG'; const _SET_STATUS_GENERATOR = '_SET_STATUS_GENERATOR'; +// TODO: consts for actions + type State = { analyticStatus: string, @@ -32,6 +35,9 @@ const store = createStore({ state.analyticUnitType = analyticUnitType; state.analyticUnitConfig = analyticUnitConfig; }, + // [PATCH_CONFIG](state, patchObj) { + // patchConfig(patchConfig) + // } [_SET_STATUS_GENERATOR](state, generator: AsyncIterableIterator) { state._statusGenerator = generator; } @@ -65,6 +71,10 @@ const store = createStore({ async fetchConfig({commit}) { const [analyticUnitType, analyticUnitConfig] = await getConfig(); commit(SET_DETECTOR_CONFIG, { analyticUnitType, analyticUnitConfig }); + }, + async patchConfig({commit}, payload) { + patchConfig(payload); + this.dispatch('fetchConfig'); } }, modules: { diff --git a/client/src/types/analytic_units/index.ts b/client/src/types/analytic_units/index.ts index f308f53..f1d2f07 100644 --- a/client/src/types/analytic_units/index.ts +++ b/client/src/types/analytic_units/index.ts @@ -10,9 +10,9 @@ import _ from 'lodash'; // TODO: move types to ./types export enum AnalyticUnitType { - PATTERN = 'pattern', - THRESHOLD = 'threshold', - ANOMALY = 'anomaly' + PATTERN = 'Pattern', + THRESHOLD = 'Threshold', + ANOMALY = 'Anomaly' } export type PatternConfig = { diff --git a/client/src/views/Home.vue b/client/src/views/Home.vue index d467d92..330534b 100644 --- a/client/src/views/Home.vue +++ b/client/src/views/Home.vue @@ -5,7 +5,7 @@
- Analytic unit type:

@@ -18,9 +18,9 @@

Correlation score: -
+
Model score: -

+

@@ -45,15 +45,13 @@ export default defineComponent({ this.$refs.graph.deleteAllSegments(); }, changeAnalyticUnitType(e) { - console.log(e); + this.$store.dispatch('patchConfig', { [e.target.value]: true } ); }, correlationScoreChange(e) { - // TODO: store value - console.log(e); + this.$store.dispatch('patchConfig', { Pattern: { correlation_score: e.target.value } }); }, modelScoreChange(e) { - // TODO: store value - console.log(e); + this.$store.dispatch('patchConfig', { Pattern: { model_score: e.target.value } }); } }, data: function () { diff --git a/server/src/api/analytics.rs b/server/src/api/analytics.rs index 2119010..13a903e 100644 --- a/server/src/api/analytics.rs +++ b/server/src/api/analytics.rs @@ -10,6 +10,7 @@ pub mod filters { list(client.clone()) .or(status(client.clone())) .or(get_config(client.clone())) + .or(put_config(client.clone())) // .or(list_train(client.clone())) // .or(create(db.clone())) // // .or(update(db.clone())) @@ -44,7 +45,18 @@ pub mod filters { warp::path!("analytics" / "config") .and(warp::get()) .and(with_client(client)) - .and_then(handlers::config) + .and_then(handlers::get_config) + } + + /// PATCH /analytics/config + pub fn put_config( + client: Client, + ) -> impl Filter + Clone { + warp::path!("analytics" / "config") + .and(warp::patch()) + .and(with_client(client)) + .and(warp::body::json()) + .and_then(handlers::patch_config) } /// GET /analytics/model @@ -66,6 +78,8 @@ pub mod filters { mod handlers { + use serde_json::Value; + use super::models::{Client, ListOptions, Status}; use crate::api::{BadQuery, API}; @@ -93,7 +107,19 @@ mod handlers { } } - pub async fn config(client: Client) -> Result { + pub async fn get_config(client: Client) -> Result { + match client.get_config().await { + Ok(cf) => Ok(API::json(&cf)), + Err(e) => { + println!("{:?}", e); + Err(warp::reject::custom(BadQuery)) + } + } + } + + pub async fn patch_config(client: Client, obj: Value) -> Result { + + println!("{:?}", obj); match client.get_config().await { Ok(cf) => Ok(API::json(&cf)), Err(e) => { diff --git a/server/src/api/mod.rs b/server/src/api/mod.rs index d187330..5d9f1c7 100644 --- a/server/src/api/mod.rs +++ b/server/src/api/mod.rs @@ -63,7 +63,7 @@ impl API<'_> { hs.insert("Access-Control-Allow-Origin", HeaderValue::from_static("*")); hs.insert( "Access-Control-Allow-Methods", - HeaderValue::from_static("POST, GET, OPTIONS, DELETE"), + HeaderValue::from_static("POST, GET, OPTIONS, DELETE, PATCH"), ); hs.insert( "Access-Control-Allow-Headers",