2020-01-29 19:37:25 +00:00
|
|
|
<template>
|
2023-03-09 10:59:11 +00:00
|
|
|
<MkContainer :show-header="widgetProps.showHeader" :style="`height: ${widgetProps.height}px;`" :scrollable="true" data-cy-mkw-timeline class="mkw-timeline">
|
2023-01-14 23:30:29 +00:00
|
|
|
<template #icon>
|
|
|
|
<i v-if="widgetProps.src === 'home'" class="ti ti-home"></i>
|
|
|
|
<i v-else-if="widgetProps.src === 'local'" class="ti ti-planet"></i>
|
|
|
|
<i v-else-if="widgetProps.src === 'social'" class="ti ti-rocket"></i>
|
|
|
|
<i v-else-if="widgetProps.src === 'global'" class="ti ti-whirl"></i>
|
|
|
|
<i v-else-if="widgetProps.src === 'list'" class="ti ti-list"></i>
|
|
|
|
<i v-else-if="widgetProps.src === 'antenna'" class="ti ti-antenna"></i>
|
|
|
|
</template>
|
2020-07-11 01:13:11 +00:00
|
|
|
<template #header>
|
2021-11-19 10:36:12 +00:00
|
|
|
<button class="_button" @click="choose">
|
2023-01-14 23:30:29 +00:00
|
|
|
<span>{{ widgetProps.src === 'list' ? widgetProps.list.name : widgetProps.src === 'antenna' ? widgetProps.antenna.name : $t('_timelines.' + widgetProps.src) }}</span>
|
2022-12-19 10:01:30 +00:00
|
|
|
<i :class="menuOpened ? 'ti ti-chevron-up' : 'ti ti-chevron-down'" style="margin-left: 8px;"></i>
|
2020-07-11 01:13:11 +00:00
|
|
|
</button>
|
|
|
|
</template>
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2020-07-11 01:13:11 +00:00
|
|
|
<div>
|
2023-02-22 02:00:34 +00:00
|
|
|
<MkTimeline :key="widgetProps.src === 'list' ? `list:${widgetProps.list.id}` : widgetProps.src === 'antenna' ? `antenna:${widgetProps.antenna.id}` : widgetProps.src" :src="widgetProps.src" :list="widgetProps.list ? widgetProps.list.id : null" :antenna="widgetProps.antenna ? widgetProps.antenna.id : null"/>
|
2020-07-11 01:13:11 +00:00
|
|
|
</div>
|
2020-10-17 11:12:00 +00:00
|
|
|
</MkContainer>
|
2020-01-29 19:37:25 +00:00
|
|
|
</template>
|
|
|
|
|
2022-01-08 11:30:01 +00:00
|
|
|
<script lang="ts" setup>
|
2023-02-16 14:09:41 +00:00
|
|
|
import { ref } from 'vue';
|
|
|
|
import { useWidgetPropsManager, Widget, WidgetComponentExpose } from './widget';
|
2022-12-31 11:40:47 +00:00
|
|
|
import { GetFormResultType } from '@/scripts/form';
|
2022-01-08 11:30:01 +00:00
|
|
|
import * as os from '@/os';
|
2022-09-06 09:21:49 +00:00
|
|
|
import MkContainer from '@/components/MkContainer.vue';
|
2023-02-22 02:00:34 +00:00
|
|
|
import MkTimeline from '@/components/MkTimeline.vue';
|
2022-01-08 11:30:01 +00:00
|
|
|
import { i18n } from '@/i18n';
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2022-01-08 11:30:01 +00:00
|
|
|
const name = 'timeline';
|
2020-10-17 11:12:00 +00:00
|
|
|
|
2022-01-08 11:30:01 +00:00
|
|
|
const widgetPropsDef = {
|
|
|
|
showHeader: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: true,
|
2020-01-29 19:37:25 +00:00
|
|
|
},
|
2022-01-08 11:30:01 +00:00
|
|
|
height: {
|
|
|
|
type: 'number' as const,
|
|
|
|
default: 300,
|
|
|
|
},
|
|
|
|
src: {
|
|
|
|
type: 'string' as const,
|
|
|
|
default: 'home',
|
|
|
|
hidden: true,
|
|
|
|
},
|
|
|
|
antenna: {
|
|
|
|
type: 'object' as const,
|
|
|
|
default: null,
|
|
|
|
hidden: true,
|
2020-01-29 19:37:25 +00:00
|
|
|
},
|
2022-01-08 11:30:01 +00:00
|
|
|
list: {
|
|
|
|
type: 'object' as const,
|
|
|
|
default: null,
|
|
|
|
hidden: true,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
|
|
|
|
|
|
|
// 現時点ではvueの制限によりimportしたtypeをジェネリックに渡せない
|
|
|
|
//const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
|
|
|
//const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
|
|
|
const props = defineProps<{ widget?: Widget<WidgetProps>; }>();
|
2022-05-25 07:43:12 +00:00
|
|
|
const emit = defineEmits<{ (ev: 'updateProps', props: WidgetProps); }>();
|
2022-01-08 11:30:01 +00:00
|
|
|
|
|
|
|
const { widgetProps, configure, save } = useWidgetPropsManager(name,
|
|
|
|
widgetPropsDef,
|
|
|
|
props,
|
|
|
|
emit,
|
|
|
|
);
|
|
|
|
|
|
|
|
const menuOpened = ref(false);
|
|
|
|
|
|
|
|
const setSrc = (src) => {
|
|
|
|
widgetProps.src = src;
|
|
|
|
save();
|
|
|
|
};
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2022-01-08 11:30:01 +00:00
|
|
|
const choose = async (ev) => {
|
|
|
|
menuOpened.value = true;
|
|
|
|
const [antennas, lists] = await Promise.all([
|
|
|
|
os.api('antennas/list'),
|
2022-12-22 07:01:59 +00:00
|
|
|
os.api('users/lists/list'),
|
2022-01-08 11:30:01 +00:00
|
|
|
]);
|
|
|
|
const antennaItems = antennas.map(antenna => ({
|
|
|
|
text: antenna.name,
|
2022-12-19 10:01:30 +00:00
|
|
|
icon: 'ti ti-antenna',
|
2022-01-08 11:30:01 +00:00
|
|
|
action: () => {
|
|
|
|
widgetProps.antenna = antenna;
|
|
|
|
setSrc('antenna');
|
2022-12-22 07:01:59 +00:00
|
|
|
},
|
2022-01-08 11:30:01 +00:00
|
|
|
}));
|
|
|
|
const listItems = lists.map(list => ({
|
|
|
|
text: list.name,
|
2022-12-19 10:01:30 +00:00
|
|
|
icon: 'ti ti-list',
|
2022-01-08 11:30:01 +00:00
|
|
|
action: () => {
|
|
|
|
widgetProps.list = list;
|
|
|
|
setSrc('list');
|
2022-12-22 07:01:59 +00:00
|
|
|
},
|
2022-01-08 11:30:01 +00:00
|
|
|
}));
|
|
|
|
os.popupMenu([{
|
2022-01-28 02:39:49 +00:00
|
|
|
text: i18n.ts._timelines.home,
|
2022-12-19 10:01:30 +00:00
|
|
|
icon: 'ti ti-home',
|
2022-12-22 07:01:59 +00:00
|
|
|
action: () => { setSrc('home'); },
|
2022-01-08 11:30:01 +00:00
|
|
|
}, {
|
2022-01-28 02:39:49 +00:00
|
|
|
text: i18n.ts._timelines.local,
|
2022-12-31 11:40:47 +00:00
|
|
|
icon: 'ti ti-planet',
|
2022-12-22 07:01:59 +00:00
|
|
|
action: () => { setSrc('local'); },
|
2022-01-08 11:30:01 +00:00
|
|
|
}, {
|
2022-01-28 02:39:49 +00:00
|
|
|
text: i18n.ts._timelines.social,
|
2022-12-31 11:40:47 +00:00
|
|
|
icon: 'ti ti-rocket',
|
2022-12-22 07:01:59 +00:00
|
|
|
action: () => { setSrc('social'); },
|
2022-01-08 11:30:01 +00:00
|
|
|
}, {
|
2022-01-28 02:39:49 +00:00
|
|
|
text: i18n.ts._timelines.global,
|
2022-12-31 11:40:47 +00:00
|
|
|
icon: 'ti ti-whirl',
|
2022-12-22 07:01:59 +00:00
|
|
|
action: () => { setSrc('global'); },
|
2022-01-28 02:53:12 +00:00
|
|
|
}, antennaItems.length > 0 ? null : undefined, ...antennaItems, listItems.length > 0 ? null : undefined, ...listItems], ev.currentTarget ?? ev.target).then(() => {
|
2022-01-08 11:30:01 +00:00
|
|
|
menuOpened.value = false;
|
|
|
|
});
|
|
|
|
};
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2022-01-08 11:30:01 +00:00
|
|
|
defineExpose<WidgetComponentExpose>({
|
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
2020-01-29 19:37:25 +00:00
|
|
|
});
|
|
|
|
</script>
|