2020-01-29 20:37:25 +01:00
|
|
|
<template>
|
2023-04-08 02:01:42 +02:00
|
|
|
<MkContainer
|
|
|
|
:show-header="widgetProps.showHeader"
|
|
|
|
:style="`height: ${widgetProps.height}px;`"
|
|
|
|
:scrollable="true"
|
|
|
|
class="mkw-timeline"
|
|
|
|
>
|
|
|
|
<template #header>
|
|
|
|
<button class="_button" @click="choose">
|
|
|
|
<i
|
|
|
|
v-if="widgetProps.src === 'home'"
|
|
|
|
class="ph-house ph-bold ph-lg"
|
|
|
|
></i>
|
|
|
|
<i
|
|
|
|
v-else-if="widgetProps.src === 'local'"
|
|
|
|
class="ph-chats-circle ph-bold ph-lg"
|
|
|
|
></i>
|
|
|
|
<i
|
|
|
|
v-else-if="widgetProps.src === 'social'"
|
|
|
|
class="ph-share-network ph-bold ph-lg"
|
|
|
|
></i>
|
|
|
|
<i
|
|
|
|
v-else-if="widgetProps.src === 'global'"
|
|
|
|
class="ph-planet ph-bold ph-lg"
|
|
|
|
></i>
|
|
|
|
<i
|
|
|
|
v-else-if="widgetProps.src === 'list'"
|
|
|
|
class="ph-list-bullets ph-bold ph-lg"
|
|
|
|
></i>
|
|
|
|
<i
|
|
|
|
v-else-if="widgetProps.src === 'antenna'"
|
|
|
|
class="ph-television ph-bold ph-lg"
|
|
|
|
></i>
|
|
|
|
<span style="margin-left: 8px">{{
|
|
|
|
widgetProps.src === "list"
|
|
|
|
? widgetProps.list.name
|
|
|
|
: widgetProps.src === "antenna"
|
|
|
|
? widgetProps.antenna.name
|
|
|
|
: i18n.t("_timelines." + widgetProps.src)
|
|
|
|
}}</span>
|
|
|
|
<i
|
|
|
|
:class="
|
|
|
|
menuOpened
|
|
|
|
? 'ph-caret-up ph-bold ph-lg'
|
|
|
|
: 'ph-caret-down ph-bold ph-lg'
|
|
|
|
"
|
|
|
|
style="margin-left: 8px"
|
|
|
|
></i>
|
|
|
|
</button>
|
|
|
|
</template>
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
<div>
|
|
|
|
<XTimeline
|
|
|
|
: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"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</MkContainer>
|
2020-01-29 20:37:25 +01:00
|
|
|
</template>
|
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
<script lang="ts" setup>
|
2023-04-08 02:01:42 +02:00
|
|
|
import { onMounted, onUnmounted, reactive, ref, watch } from "vue";
|
|
|
|
import { GetFormResultType } from "@/scripts/form";
|
|
|
|
import {
|
|
|
|
useWidgetPropsManager,
|
|
|
|
Widget,
|
|
|
|
WidgetComponentEmits,
|
|
|
|
WidgetComponentExpose,
|
|
|
|
WidgetComponentProps,
|
|
|
|
} from "./widget";
|
|
|
|
import * as os from "@/os";
|
|
|
|
import MkContainer from "@/components/MkContainer.vue";
|
|
|
|
import XTimeline from "@/components/MkTimeline.vue";
|
|
|
|
import { $i } from "@/account";
|
|
|
|
import { i18n } from "@/i18n";
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
const name = "timeline";
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
const widgetPropsDef = {
|
|
|
|
showHeader: {
|
2023-04-08 02:01:42 +02:00
|
|
|
type: "boolean" as const,
|
2022-01-08 12:30:01 +01:00
|
|
|
default: true,
|
2020-01-29 20:37:25 +01:00
|
|
|
},
|
2022-01-08 12:30:01 +01:00
|
|
|
height: {
|
2023-04-08 02:01:42 +02:00
|
|
|
type: "number" as const,
|
2022-01-08 12:30:01 +01:00
|
|
|
default: 300,
|
|
|
|
},
|
|
|
|
src: {
|
2023-04-08 02:01:42 +02:00
|
|
|
type: "string" as const,
|
|
|
|
default: "home",
|
2022-01-08 12:30:01 +01:00
|
|
|
hidden: true,
|
|
|
|
},
|
|
|
|
antenna: {
|
2023-04-08 02:01:42 +02:00
|
|
|
type: "object" as const,
|
2022-01-08 12:30:01 +01:00
|
|
|
default: null,
|
|
|
|
hidden: true,
|
2020-01-29 20:37:25 +01:00
|
|
|
},
|
2022-01-08 12:30:01 +01:00
|
|
|
list: {
|
2023-04-08 02:01:42 +02:00
|
|
|
type: "object" as const,
|
2022-01-08 12:30:01 +01:00
|
|
|
default: null,
|
|
|
|
hidden: true,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
|
|
|
|
|
|
|
// 現時点ではvueの制限によりimportしたtypeをジェネリックに渡せない
|
|
|
|
//const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
|
|
|
//const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
2023-04-08 02:01:42 +02:00
|
|
|
const props = defineProps<{ widget?: Widget<WidgetProps> }>();
|
|
|
|
const emit = defineEmits<{ (ev: "updateProps", props: WidgetProps) }>();
|
2022-01-08 12:30:01 +01:00
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
const { widgetProps, configure, save } = useWidgetPropsManager(
|
|
|
|
name,
|
2022-01-08 12:30:01 +01:00
|
|
|
widgetPropsDef,
|
|
|
|
props,
|
2023-04-08 02:01:42 +02:00
|
|
|
emit
|
2022-01-08 12:30:01 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
const menuOpened = ref(false);
|
|
|
|
|
|
|
|
const setSrc = (src) => {
|
|
|
|
widgetProps.src = src;
|
|
|
|
save();
|
|
|
|
};
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
const choose = async (ev) => {
|
|
|
|
menuOpened.value = true;
|
|
|
|
const [antennas, lists] = await Promise.all([
|
2023-04-08 02:01:42 +02:00
|
|
|
os.api("antennas/list"),
|
|
|
|
os.api("users/lists/list"),
|
2022-01-08 12:30:01 +01:00
|
|
|
]);
|
2023-04-08 02:01:42 +02:00
|
|
|
const antennaItems = antennas.map((antenna) => ({
|
2022-01-08 12:30:01 +01:00
|
|
|
text: antenna.name,
|
2023-04-08 02:01:42 +02:00
|
|
|
icon: "ph-flying-saucer ph-bold ph-lg",
|
2022-01-08 12:30:01 +01:00
|
|
|
action: () => {
|
|
|
|
widgetProps.antenna = antenna;
|
2023-04-08 02:01:42 +02:00
|
|
|
setSrc("antenna");
|
|
|
|
},
|
2022-01-08 12:30:01 +01:00
|
|
|
}));
|
2023-04-08 02:01:42 +02:00
|
|
|
const listItems = lists.map((list) => ({
|
2022-01-08 12:30:01 +01:00
|
|
|
text: list.name,
|
2023-04-08 02:01:42 +02:00
|
|
|
icon: "ph-list-bullets ph-bold ph-lg",
|
2022-01-08 12:30:01 +01:00
|
|
|
action: () => {
|
|
|
|
widgetProps.list = list;
|
2023-04-08 02:01:42 +02:00
|
|
|
setSrc("list");
|
|
|
|
},
|
2022-01-08 12:30:01 +01:00
|
|
|
}));
|
2023-04-08 02:01:42 +02:00
|
|
|
os.popupMenu(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
text: i18n.ts._timelines.home,
|
|
|
|
icon: "ph-house ph-bold ph-lg",
|
|
|
|
action: () => {
|
|
|
|
setSrc("home");
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: i18n.ts._timelines.local,
|
|
|
|
icon: "ph-chats-teardrop ph-bold ph-lg",
|
|
|
|
action: () => {
|
|
|
|
setSrc("local");
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: i18n.ts._timelines.social,
|
|
|
|
icon: "ph-share-network ph-bold ph-lg",
|
|
|
|
action: () => {
|
|
|
|
setSrc("social");
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: i18n.ts._timelines.global,
|
|
|
|
icon: "ph-planet ph-bold ph-lg",
|
|
|
|
action: () => {
|
|
|
|
setSrc("global");
|
|
|
|
},
|
|
|
|
},
|
|
|
|
antennaItems.length > 0 ? null : undefined,
|
|
|
|
...antennaItems,
|
|
|
|
listItems.length > 0 ? null : undefined,
|
|
|
|
...listItems,
|
|
|
|
],
|
|
|
|
ev.currentTarget ?? ev.target
|
|
|
|
).then(() => {
|
2022-01-08 12:30:01 +01:00
|
|
|
menuOpened.value = false;
|
|
|
|
});
|
|
|
|
};
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
defineExpose<WidgetComponentExpose>({
|
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
2020-01-29 20:37:25 +01:00
|
|
|
});
|
|
|
|
</script>
|