enhance(ad): 広告掲載ページにてfilterをわかりやすく (misskey-dev#12385) (MisskeyIO#243)
Co-authored-by: nenohi <kimutipartylove@gmail.com>
This commit is contained in:
parent
d2b2beef80
commit
5c4dfd3948
@ -22,7 +22,7 @@ export const paramDef = {
|
|||||||
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
|
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
|
||||||
sinceId: { type: 'string', format: 'misskey:id' },
|
sinceId: { type: 'string', format: 'misskey:id' },
|
||||||
untilId: { type: 'string', format: 'misskey:id' },
|
untilId: { type: 'string', format: 'misskey:id' },
|
||||||
publishing: { type: 'boolean', default: false },
|
publishing: { type: 'boolean', default: null, nullable: true },
|
||||||
},
|
},
|
||||||
required: [],
|
required: [],
|
||||||
} as const;
|
} as const;
|
||||||
@ -37,8 +37,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||||||
) {
|
) {
|
||||||
super(meta, paramDef, async (ps, me) => {
|
super(meta, paramDef, async (ps, me) => {
|
||||||
const query = this.queryService.makePaginationQuery(this.adsRepository.createQueryBuilder('ad'), ps.sinceId, ps.untilId);
|
const query = this.queryService.makePaginationQuery(this.adsRepository.createQueryBuilder('ad'), ps.sinceId, ps.untilId);
|
||||||
if (ps.publishing) {
|
if (ps.publishing === true) {
|
||||||
query.andWhere('ad.expiresAt > :now', { now: new Date() }).andWhere('ad.startsAt <= :now', { now: new Date() });
|
query.andWhere('ad.expiresAt > :now', { now: new Date() }).andWhere('ad.startsAt <= :now', { now: new Date() });
|
||||||
|
} else if (ps.publishing === false) {
|
||||||
|
query.andWhere('ad.expiresAt <= :now', { now: new Date() }).orWhere('ad.startsAt > :now', { now: new Date() });
|
||||||
}
|
}
|
||||||
const ads = await query.limit(ps.limit).getMany();
|
const ads = await query.limit(ps.limit).getMany();
|
||||||
|
|
||||||
|
@ -9,12 +9,15 @@ SPDX-License-Identifier: AGPL-3.0-only
|
|||||||
<XHeader :actions="headerActions" :tabs="headerTabs"/>
|
<XHeader :actions="headerActions" :tabs="headerTabs"/>
|
||||||
</template>
|
</template>
|
||||||
<MkSpacer :contentMax="900">
|
<MkSpacer :contentMax="900">
|
||||||
<MkSwitch :modelValue="publishing" @update:modelValue="onChangePublishing">
|
<MkSelect v-model="filterType" :class="$style.input" @update:modelValue="filterItems">
|
||||||
{{ i18n.ts.publishing }}
|
<template #label>{{ i18n.ts.state }}</template>
|
||||||
</MkSwitch>
|
<option value="all">{{ i18n.ts.all }}</option>
|
||||||
|
<option value="publishing">{{ i18n.ts.publishing }}</option>
|
||||||
|
<option value="expired">{{ i18n.ts.expired }}</option>
|
||||||
|
</MkSelect>
|
||||||
<div>
|
<div>
|
||||||
<div v-for="ad in ads" class="_panel _gaps_m" :class="$style.ad">
|
<div v-for="ad in ads" class="_panel _gaps_m" :class="$style.ad">
|
||||||
<MkAd v-if="ad.url" :specify="ad"/>
|
<MkAd v-if="ad.url" :key="ad.id" :specify="ad"/>
|
||||||
<MkInput v-model="ad.url" type="url">
|
<MkInput v-model="ad.url" type="url">
|
||||||
<template #label>URL</template>
|
<template #label>URL</template>
|
||||||
</MkInput>
|
</MkInput>
|
||||||
@ -82,14 +85,14 @@ SPDX-License-Identifier: AGPL-3.0-only
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { } from 'vue';
|
import { ref } from 'vue';
|
||||||
import XHeader from './_header_.vue';
|
import XHeader from './_header_.vue';
|
||||||
import MkButton from '@/components/MkButton.vue';
|
import MkButton from '@/components/MkButton.vue';
|
||||||
import MkInput from '@/components/MkInput.vue';
|
import MkInput from '@/components/MkInput.vue';
|
||||||
import MkTextarea from '@/components/MkTextarea.vue';
|
import MkTextarea from '@/components/MkTextarea.vue';
|
||||||
import MkRadios from '@/components/MkRadios.vue';
|
import MkRadios from '@/components/MkRadios.vue';
|
||||||
import MkFolder from '@/components/MkFolder.vue';
|
import MkFolder from '@/components/MkFolder.vue';
|
||||||
import MkSwitch from '@/components/MkSwitch.vue';
|
import MkSelect from '@/components/MkSelect.vue';
|
||||||
import FormSplit from '@/components/form/split.vue';
|
import FormSplit from '@/components/form/split.vue';
|
||||||
import * as os from '@/os.js';
|
import * as os from '@/os.js';
|
||||||
import { i18n } from '@/i18n.js';
|
import { i18n } from '@/i18n.js';
|
||||||
@ -101,24 +104,34 @@ let ads: any[] = $ref([]);
|
|||||||
const localTime = new Date();
|
const localTime = new Date();
|
||||||
const localTimeDiff = localTime.getTimezoneOffset() * 60 * 1000;
|
const localTimeDiff = localTime.getTimezoneOffset() * 60 * 1000;
|
||||||
const daysOfWeek: string[] = [i18n.ts._weekday.sunday, i18n.ts._weekday.monday, i18n.ts._weekday.tuesday, i18n.ts._weekday.wednesday, i18n.ts._weekday.thursday, i18n.ts._weekday.friday, i18n.ts._weekday.saturday];
|
const daysOfWeek: string[] = [i18n.ts._weekday.sunday, i18n.ts._weekday.monday, i18n.ts._weekday.tuesday, i18n.ts._weekday.wednesday, i18n.ts._weekday.thursday, i18n.ts._weekday.friday, i18n.ts._weekday.saturday];
|
||||||
let publishing = false;
|
const filterType = ref('all');
|
||||||
|
let publishing: boolean | null = null;
|
||||||
|
|
||||||
os.api('admin/ad/list', { publishing: publishing }).then(adsResponse => {
|
os.api('admin/ad/list', { publishing: publishing }).then(adsResponse => {
|
||||||
ads = adsResponse.map(r => {
|
if (adsResponse != null) {
|
||||||
const exdate = new Date(r.expiresAt);
|
ads = adsResponse.map(r => {
|
||||||
const stdate = new Date(r.startsAt);
|
const exdate = new Date(r.expiresAt);
|
||||||
exdate.setMilliseconds(exdate.getMilliseconds() - localTimeDiff);
|
const stdate = new Date(r.startsAt);
|
||||||
stdate.setMilliseconds(stdate.getMilliseconds() - localTimeDiff);
|
exdate.setMilliseconds(exdate.getMilliseconds() - localTimeDiff);
|
||||||
return {
|
stdate.setMilliseconds(stdate.getMilliseconds() - localTimeDiff);
|
||||||
...r,
|
return {
|
||||||
expiresAt: exdate.toISOString().slice(0, 16),
|
...r,
|
||||||
startsAt: stdate.toISOString().slice(0, 16),
|
expiresAt: exdate.toISOString().slice(0, 16),
|
||||||
};
|
startsAt: stdate.toISOString().slice(0, 16),
|
||||||
});
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const onChangePublishing = (v) => {
|
const filterItems = (v) => {
|
||||||
publishing = v;
|
if (v === 'publishing') {
|
||||||
|
publishing = true;
|
||||||
|
} else if (v === 'expired') {
|
||||||
|
publishing = false;
|
||||||
|
} else {
|
||||||
|
publishing = null;
|
||||||
|
}
|
||||||
|
|
||||||
refresh();
|
refresh();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -197,6 +210,7 @@ function save(ad) {
|
|||||||
|
|
||||||
function more() {
|
function more() {
|
||||||
os.api('admin/ad/list', { untilId: ads.reduce((acc, ad) => ad.id != null ? ad : acc).id, publishing: publishing }).then(adsResponse => {
|
os.api('admin/ad/list', { untilId: ads.reduce((acc, ad) => ad.id != null ? ad : acc).id, publishing: publishing }).then(adsResponse => {
|
||||||
|
if (adsResponse == null) return;
|
||||||
ads = ads.concat(adsResponse.map(r => {
|
ads = ads.concat(adsResponse.map(r => {
|
||||||
const exdate = new Date(r.expiresAt);
|
const exdate = new Date(r.expiresAt);
|
||||||
const stdate = new Date(r.startsAt);
|
const stdate = new Date(r.startsAt);
|
||||||
@ -213,6 +227,7 @@ function more() {
|
|||||||
|
|
||||||
function refresh() {
|
function refresh() {
|
||||||
os.api('admin/ad/list', { publishing: publishing }).then(adsResponse => {
|
os.api('admin/ad/list', { publishing: publishing }).then(adsResponse => {
|
||||||
|
if (adsResponse == null) return;
|
||||||
ads = adsResponse.map(r => {
|
ads = adsResponse.map(r => {
|
||||||
const exdate = new Date(r.expiresAt);
|
const exdate = new Date(r.expiresAt);
|
||||||
const stdate = new Date(r.startsAt);
|
const stdate = new Date(r.startsAt);
|
||||||
@ -252,4 +267,7 @@ definePageMetadata({
|
|||||||
margin-bottom: var(--margin);
|
margin-bottom: var(--margin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.input {
|
||||||
|
margin-bottom: 32px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
Loading…
Reference in New Issue
Block a user