-
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
4 changed files
with
190 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
<template> | ||
<div class="text-left h-100"> | ||
<div class="sample-widget"> | ||
<H2> This is a sample widget</H2> | ||
<h3>Bucketting field : {{ props.widgetSettings.buckettingField }}</h3> | ||
|
||
<KTable :items="data" :total="data.length" :headers="headers"> | ||
<template #cell(name)="data"> | ||
{{ data.item.key }} | ||
</template> | ||
<template #cell(description)="data"> | ||
{{ data.item.count }} | ||
</template> | ||
</KTable> | ||
|
||
<b-container fluid> | ||
<brow v-for="e in data" :key="e.key"> | ||
<bcol > | ||
{{ e.key }} | ||
</bcol> | ||
<bcol cols="6"> | ||
{{ e.count }} | ||
</bcol> | ||
<div class="w-100"></div> | ||
</brow> | ||
</b-container> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { computed, onMounted, ref, watch, reactive } from 'vue'; | ||
import { useKuzzle, useI18n, AggregateTypes, KTable, KTableHeader } from '@kuzzleio/iot-platform-frontend'; | ||
import type { AssetContent } from 'kuzzle-device-manager-types'; | ||
import { KDocument } from 'kuzzle-sdk'; | ||
import { BFormSelect, BFormSelectOption, BRow, BCol, BFormInput, BButton } from 'bootstrap-vue'; | ||
// import { KTableContext, KTableHeader, AlertRuleContent, SortQuery } from '@/types'; | ||
// Types | ||
import {SampleWidgetSettingsType} from "./SampleWidgetSettings" | ||
import { forEach } from 'lodash'; | ||
// Props | ||
interface SampleWidgetProps { | ||
widgetSettings: SampleWidgetSettingsType; | ||
widgetHeight: number; | ||
widgetWidth: string; | ||
engineIndex: string; | ||
} | ||
const props = defineProps<SampleWidgetProps>(); | ||
// Computeds | ||
const headers = computed<KTableHeader[]>(() => [ | ||
{ | ||
key: 'name', | ||
label: 'Colonne 1', //$i18n.t('locales.notifications.list.notificationName'), | ||
sortable: true, | ||
}, | ||
{ | ||
key: 'description', | ||
label: 'Colonne 2', //$i18n.t('locales.notifications.list.notificationDescription'), | ||
sortable: false, | ||
}, | ||
]); | ||
// Emits | ||
interface EmitTypes { | ||
(name: 'loading'): void; | ||
(name: 'loaded'): void; | ||
} | ||
const emit = defineEmits<EmitTypes>(); | ||
// Composables | ||
const $i18n = useI18n(); | ||
const $kuzzle = useKuzzle(); | ||
// Refs | ||
const data = ref<Array<{[x:string] : number;}>>([]); | ||
// Constants | ||
// Computeds | ||
// Hooks | ||
onMounted(async () => { | ||
emit('loading'); | ||
console.log("onmounted!!!!!"); | ||
await fetchData(); | ||
// kuzzle search avec props buckettingField | ||
// charger les données dans un chartjs | ||
// update front | ||
emit('loaded'); | ||
}); | ||
// Functions | ||
async function fetchData(): Promise<void> { | ||
if (props.widgetSettings?.buckettingField) { | ||
const query = { | ||
equals: { | ||
model: 'Lampadaire', | ||
}, | ||
}; | ||
const res= await $kuzzle.document.search<AssetContent>( | ||
props.engineIndex, | ||
'assets', | ||
{ aggs: { | ||
term_agg: { | ||
terms : { | ||
field: 'metadata.' + props.widgetSettings.buckettingField, | ||
} | ||
} | ||
} }, | ||
); | ||
const agg : Array<{[x:string] : number;}> = [] ; | ||
for( let bucket of res.aggregations?.term_agg.buckets) { | ||
agg.push( { key : bucket.key, count: bucket.doc_count}); | ||
} | ||
data.value= agg; | ||
} | ||
emit('loaded'); | ||
} | ||
</script> | ||
|
||
<style lang="scss"></style> |
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,53 @@ | ||
<template> | ||
<div> | ||
<h1>Widget form</h1> | ||
<BRow> | ||
<BCol> | ||
<BFormGroup | ||
:label="$i18n.t('locales.widget.common.asset-model')" | ||
label-for="asset-model-field" | ||
> | ||
<BFormInput | ||
id="asset-model-field" | ||
v-model="widgetSettings.buckettingField" | ||
required | ||
@change="emitChange" | ||
/> | ||
</BFormGroup> | ||
</BCol> | ||
</BRow> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { BFormSelect, BFormSelectOption, BRow, BCol, BFormInput, BButton } from 'bootstrap-vue'; | ||
import { reactive } from 'vue'; | ||
import cloneDeep from 'lodash/cloneDeep'; | ||
// Types | ||
import { SampleWidgetSettingsType } from './SampleWidgetSettings'; | ||
export interface SampleWidgetFormProps { | ||
// The index name where the Dashboard engine is installed | ||
engineIndex: string; | ||
// The collections of the engine-index | ||
collections: string[]; | ||
// The settings, passed to the widget | ||
editedWidgetSettings?: SampleWidgetSettingsType; | ||
} | ||
const props = withDefaults(defineProps<SampleWidgetFormProps>(), { | ||
editedWidgetSettings: () => ({ | ||
buckettingField: 'test', | ||
}), | ||
}); | ||
// Refs | ||
const widgetSettings = reactive(cloneDeep(props.editedWidgetSettings)); | ||
// Emits | ||
type EmitTypes = (name: 'change', widgetSettings: SampleWidgetSettingsType) => void; | ||
const emit = defineEmits<EmitTypes>(); | ||
function emitChange(): void { | ||
emit('change', widgetSettings); | ||
} | ||
</script> |
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,3 @@ | ||
export interface SampleWidgetSettingsType { | ||
buckettingField: string; | ||
} |