2020-01-29 13:37:25 -06:00
|
|
|
<template>
|
2022-05-28 00:28:12 -05:00
|
|
|
<MkContainer :show-header="widgetProps.showHeader" :style="`height: ${widgetProps.height}px;`" :scrollable="true" class="mkw-timeline">
|
2020-07-10 20:13:11 -05:00
|
|
|
<template #header>
|
2021-11-19 04:36:12 -06:00
|
|
|
<button class="_button" @click="choose">
|
2022-12-18 22:54:35 -06:00
|
|
|
<i v-if="widgetProps.src === 'home'" class="fas fa-home"></i>
|
|
|
|
<i v-else-if="widgetProps.src === 'local'" class="fas fa-comments"></i>
|
|
|
|
<i v-else-if="widgetProps.src === 'social'" class="fas fa-share-alt"></i>
|
|
|
|
<i v-else-if="widgetProps.src === 'global'" class="fas fa-globe"></i>
|
2022-01-08 05:30:01 -06:00
|
|
|
<i v-else-if="widgetProps.src === 'list'" class="fas fa-list-ul"></i>
|
|
|
|
<i v-else-if="widgetProps.src === 'antenna'" class="fas fa-satellite"></i>
|
|
|
|
<span style="margin-left: 8px;">{{ widgetProps.src === 'list' ? widgetProps.list.name : widgetProps.src === 'antenna' ? widgetProps.antenna.name : $t('_timelines.' + widgetProps.src) }}</span>
|
2021-04-20 09:22:59 -05:00
|
|
|
<i :class="menuOpened ? 'fas fa-angle-up' : 'fas fa-angle-down'" style="margin-left: 8px;"></i>
|
2020-07-10 20:13:11 -05:00
|
|
|
</button>
|
|
|
|
</template>
|
2020-01-29 13:37:25 -06:00
|
|
|
|
2020-07-10 20:13:11 -05:00
|
|
|
<div>
|
2022-01-08 05:30:01 -06:00
|
|
|
<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"/>
|
2020-07-10 20:13:11 -05:00
|
|
|
</div>
|
2020-10-17 06:12:00 -05:00
|
|
|
</MkContainer>
|
2020-01-29 13:37:25 -06:00
|
|
|
</template>
|
|
|
|
|
2022-01-08 05:30:01 -06:00
|
|
|
<script lang="ts" setup>
|
|
|
|
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';
|
2022-09-06 04:21:49 -05:00
|
|
|
import MkContainer from '@/components/MkContainer.vue';
|
2022-08-30 10:24:33 -05:00
|
|
|
import XTimeline from '@/components/MkTimeline.vue';
|
2022-01-08 05:30:01 -06:00
|
|
|
import { $i } from '@/account';
|
|
|
|
import { i18n } from '@/i18n';
|
2020-01-29 13:37:25 -06:00
|
|
|
|
2022-01-08 05:30:01 -06:00
|
|
|
const name = 'timeline';
|
2020-10-17 06:12:00 -05:00
|
|
|
|
2022-01-08 05:30:01 -06:00
|
|
|
const widgetPropsDef = {
|
|
|
|
showHeader: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: true,
|
2020-01-29 13:37:25 -06:00
|
|
|
},
|
2022-01-08 05:30:01 -06: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 13:37:25 -06:00
|
|
|
},
|
2022-01-08 05:30:01 -06: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 02:43:12 -05:00
|
|
|
const emit = defineEmits<{ (ev: 'updateProps', props: WidgetProps); }>();
|
2022-01-08 05:30:01 -06:00
|
|
|
|
|
|
|
const { widgetProps, configure, save } = useWidgetPropsManager(name,
|
|
|
|
widgetPropsDef,
|
|
|
|
props,
|
|
|
|
emit,
|
|
|
|
);
|
|
|
|
|
|
|
|
const menuOpened = ref(false);
|
|
|
|
|
|
|
|
const setSrc = (src) => {
|
|
|
|
widgetProps.src = src;
|
|
|
|
save();
|
|
|
|
};
|
2020-01-29 13:37:25 -06:00
|
|
|
|
2022-01-08 05:30:01 -06:00
|
|
|
const choose = async (ev) => {
|
|
|
|
menuOpened.value = true;
|
|
|
|
const [antennas, lists] = await Promise.all([
|
|
|
|
os.api('antennas/list'),
|
|
|
|
os.api('users/lists/list')
|
|
|
|
]);
|
|
|
|
const antennaItems = antennas.map(antenna => ({
|
|
|
|
text: antenna.name,
|
|
|
|
icon: 'fas fa-satellite',
|
|
|
|
action: () => {
|
|
|
|
widgetProps.antenna = antenna;
|
|
|
|
setSrc('antenna');
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
const listItems = lists.map(list => ({
|
|
|
|
text: list.name,
|
|
|
|
icon: 'fas fa-list-ul',
|
|
|
|
action: () => {
|
|
|
|
widgetProps.list = list;
|
|
|
|
setSrc('list');
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
os.popupMenu([{
|
2022-01-27 20:39:49 -06:00
|
|
|
text: i18n.ts._timelines.home,
|
2022-12-18 22:54:35 -06:00
|
|
|
icon: 'fas fa-home',
|
2022-06-10 00:36:55 -05:00
|
|
|
action: () => { setSrc('home'); }
|
2022-01-08 05:30:01 -06:00
|
|
|
}, {
|
2022-01-27 20:39:49 -06:00
|
|
|
text: i18n.ts._timelines.local,
|
2022-12-18 22:54:35 -06:00
|
|
|
icon: 'fas fa-comments',
|
2022-06-10 00:36:55 -05:00
|
|
|
action: () => { setSrc('local'); }
|
2022-01-08 05:30:01 -06:00
|
|
|
}, {
|
2022-01-27 20:39:49 -06:00
|
|
|
text: i18n.ts._timelines.social,
|
2022-12-18 22:54:35 -06:00
|
|
|
icon: 'fas fa-share-alt',
|
2022-06-10 00:36:55 -05:00
|
|
|
action: () => { setSrc('social'); }
|
2022-01-08 05:30:01 -06:00
|
|
|
}, {
|
2022-01-27 20:39:49 -06:00
|
|
|
text: i18n.ts._timelines.global,
|
2022-12-18 22:54:35 -06:00
|
|
|
icon: 'fas fa-globe',
|
2022-06-10 00:36:55 -05:00
|
|
|
action: () => { setSrc('global'); }
|
2022-01-27 20:53:12 -06:00
|
|
|
}, antennaItems.length > 0 ? null : undefined, ...antennaItems, listItems.length > 0 ? null : undefined, ...listItems], ev.currentTarget ?? ev.target).then(() => {
|
2022-01-08 05:30:01 -06:00
|
|
|
menuOpened.value = false;
|
|
|
|
});
|
|
|
|
};
|
2020-01-29 13:37:25 -06:00
|
|
|
|
2022-01-08 05:30:01 -06:00
|
|
|
defineExpose<WidgetComponentExpose>({
|
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
2020-01-29 13:37:25 -06:00
|
|
|
});
|
|
|
|
</script>
|