2020-01-29 20:37:25 +01:00
|
|
|
<template>
|
2021-08-07 10:55:16 +02:00
|
|
|
<div class="shaynizk">
|
|
|
|
<div class="form">
|
|
|
|
<MkInput v-model="name" class="_inputNoTopMargin">
|
2021-08-06 15:29:19 +02:00
|
|
|
<template #label>{{ $ts.name }}</template>
|
2020-10-17 13:12:00 +02:00
|
|
|
</MkInput>
|
2021-08-06 15:29:19 +02:00
|
|
|
<MkSelect v-model="src">
|
2020-12-26 02:47:36 +01:00
|
|
|
<template #label>{{ $ts.antennaSource }}</template>
|
|
|
|
<option value="all">{{ $ts._antennaSources.all }}</option>
|
|
|
|
<option value="home">{{ $ts._antennaSources.homeTimeline }}</option>
|
|
|
|
<option value="users">{{ $ts._antennaSources.users }}</option>
|
|
|
|
<option value="list">{{ $ts._antennaSources.userList }}</option>
|
|
|
|
<option value="group">{{ $ts._antennaSources.userGroup }}</option>
|
2020-10-17 13:12:00 +02:00
|
|
|
</MkSelect>
|
2021-08-06 15:29:19 +02:00
|
|
|
<MkSelect v-model="userListId" v-if="src === 'list'">
|
2020-12-26 02:47:36 +01:00
|
|
|
<template #label>{{ $ts.userList }}</template>
|
2020-01-29 20:37:25 +01:00
|
|
|
<option v-for="list in userLists" :value="list.id" :key="list.id">{{ list.name }}</option>
|
2020-10-17 13:12:00 +02:00
|
|
|
</MkSelect>
|
2021-08-06 15:29:19 +02:00
|
|
|
<MkSelect v-model="userGroupId" v-else-if="src === 'group'">
|
2020-12-26 02:47:36 +01:00
|
|
|
<template #label>{{ $ts.userGroup }}</template>
|
2020-02-14 17:03:59 +01:00
|
|
|
<option v-for="group in userGroups" :value="group.id" :key="group.id">{{ group.name }}</option>
|
2020-10-17 13:12:00 +02:00
|
|
|
</MkSelect>
|
2021-08-06 15:29:19 +02:00
|
|
|
<MkTextarea v-model="users" v-else-if="src === 'users'">
|
|
|
|
<template #label>{{ $ts.users }}</template>
|
|
|
|
<template #caption>{{ $ts.antennaUsersDescription }} <button class="_textButton" @click="addUser">{{ $ts.addUser }}</button></template>
|
2020-10-17 13:12:00 +02:00
|
|
|
</MkTextarea>
|
2021-08-06 15:29:19 +02:00
|
|
|
<MkSwitch v-model="withReplies">{{ $ts.withReplies }}</MkSwitch>
|
|
|
|
<MkTextarea v-model="keywords">
|
|
|
|
<template #label>{{ $ts.antennaKeywords }}</template>
|
|
|
|
<template #caption>{{ $ts.antennaKeywordsDescription }}</template>
|
2020-10-17 13:12:00 +02:00
|
|
|
</MkTextarea>
|
2021-08-06 15:29:19 +02:00
|
|
|
<MkTextarea v-model="excludeKeywords">
|
|
|
|
<template #label>{{ $ts.antennaExcludeKeywords }}</template>
|
|
|
|
<template #caption>{{ $ts.antennaKeywordsDescription }}</template>
|
2020-10-17 13:12:00 +02:00
|
|
|
</MkTextarea>
|
2021-08-06 15:29:19 +02:00
|
|
|
<MkSwitch v-model="caseSensitive">{{ $ts.caseSensitive }}</MkSwitch>
|
|
|
|
<MkSwitch v-model="withFile">{{ $ts.withFileAntenna }}</MkSwitch>
|
|
|
|
<MkSwitch v-model="notify">{{ $ts.notifyAntenna }}</MkSwitch>
|
2020-01-29 20:37:25 +01:00
|
|
|
</div>
|
2021-08-07 10:55:16 +02:00
|
|
|
<div class="actions">
|
2021-04-20 16:22:59 +02:00
|
|
|
<MkButton inline @click="saveAntenna()" primary><i class="fas fa-save"></i> {{ $ts.save }}</MkButton>
|
2021-08-07 10:55:16 +02:00
|
|
|
<MkButton inline @click="deleteAntenna()" v-if="antenna.id != null" danger><i class="fas fa-trash"></i> {{ $ts.delete }}</MkButton>
|
2020-01-29 20:37:25 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 13:12:00 +02:00
|
|
|
import { defineComponent } from 'vue';
|
2021-03-23 09:30:14 +01:00
|
|
|
import MkButton from '@client/components/ui/button.vue';
|
|
|
|
import MkInput from '@client/components/ui/input.vue';
|
|
|
|
import MkTextarea from '@client/components/ui/textarea.vue';
|
|
|
|
import MkSelect from '@client/components/ui/select.vue';
|
|
|
|
import MkSwitch from '@client/components/ui/switch.vue';
|
2021-07-15 13:45:32 +02:00
|
|
|
import { getAcct } from '@/misc/acct';
|
2021-03-23 09:30:14 +01:00
|
|
|
import * as os from '@client/os';
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
export default defineComponent({
|
2020-01-29 20:37:25 +01:00
|
|
|
components: {
|
|
|
|
MkButton, MkInput, MkTextarea, MkSelect, MkSwitch
|
|
|
|
},
|
|
|
|
|
|
|
|
props: {
|
|
|
|
antenna: {
|
|
|
|
type: Object,
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
name: '',
|
|
|
|
src: '',
|
|
|
|
userListId: null,
|
2020-02-14 17:03:59 +01:00
|
|
|
userGroupId: null,
|
2020-01-29 20:37:25 +01:00
|
|
|
users: '',
|
|
|
|
keywords: '',
|
2020-02-20 16:28:45 +01:00
|
|
|
excludeKeywords: '',
|
2020-01-29 20:37:25 +01:00
|
|
|
caseSensitive: false,
|
|
|
|
withReplies: false,
|
|
|
|
withFile: false,
|
|
|
|
notify: false,
|
|
|
|
userLists: null,
|
2020-02-14 17:03:59 +01:00
|
|
|
userGroups: null,
|
2020-01-29 20:37:25 +01:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
async src() {
|
|
|
|
if (this.src === 'list' && this.userLists === null) {
|
2020-10-17 13:12:00 +02:00
|
|
|
this.userLists = await os.api('users/lists/list');
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
2020-02-14 17:03:59 +01:00
|
|
|
|
|
|
|
if (this.src === 'group' && this.userGroups === null) {
|
2020-10-17 13:12:00 +02:00
|
|
|
const groups1 = await os.api('users/groups/owned');
|
|
|
|
const groups2 = await os.api('users/groups/joined');
|
2020-02-14 17:03:59 +01:00
|
|
|
|
|
|
|
this.userGroups = [...groups1, ...groups2];
|
|
|
|
}
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
created() {
|
|
|
|
this.name = this.antenna.name;
|
|
|
|
this.src = this.antenna.src;
|
|
|
|
this.userListId = this.antenna.userListId;
|
2020-02-14 17:03:59 +01:00
|
|
|
this.userGroupId = this.antenna.userGroupId;
|
2020-01-29 20:37:25 +01:00
|
|
|
this.users = this.antenna.users.join('\n');
|
|
|
|
this.keywords = this.antenna.keywords.map(x => x.join(' ')).join('\n');
|
2020-02-20 16:28:45 +01:00
|
|
|
this.excludeKeywords = this.antenna.excludeKeywords.map(x => x.join(' ')).join('\n');
|
2020-01-29 20:37:25 +01:00
|
|
|
this.caseSensitive = this.antenna.caseSensitive;
|
|
|
|
this.withReplies = this.antenna.withReplies;
|
|
|
|
this.withFile = this.antenna.withFile;
|
|
|
|
this.notify = this.antenna.notify;
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
async saveAntenna() {
|
|
|
|
if (this.antenna.id == null) {
|
2021-08-07 10:55:16 +02:00
|
|
|
await os.apiWithDialog('antennas/create', {
|
2020-01-29 20:37:25 +01:00
|
|
|
name: this.name,
|
|
|
|
src: this.src,
|
|
|
|
userListId: this.userListId,
|
2020-02-14 17:03:59 +01:00
|
|
|
userGroupId: this.userGroupId,
|
2020-01-29 20:37:25 +01:00
|
|
|
withReplies: this.withReplies,
|
|
|
|
withFile: this.withFile,
|
|
|
|
notify: this.notify,
|
|
|
|
caseSensitive: this.caseSensitive,
|
|
|
|
users: this.users.trim().split('\n').map(x => x.trim()),
|
2020-02-20 16:28:45 +01:00
|
|
|
keywords: this.keywords.trim().split('\n').map(x => x.trim().split(' ')),
|
|
|
|
excludeKeywords: this.excludeKeywords.trim().split('\n').map(x => x.trim().split(' ')),
|
2020-01-29 20:37:25 +01:00
|
|
|
});
|
|
|
|
this.$emit('created');
|
|
|
|
} else {
|
2021-08-07 10:55:16 +02:00
|
|
|
await os.apiWithDialog('antennas/update', {
|
2020-01-29 20:37:25 +01:00
|
|
|
antennaId: this.antenna.id,
|
|
|
|
name: this.name,
|
|
|
|
src: this.src,
|
|
|
|
userListId: this.userListId,
|
2020-02-14 17:03:59 +01:00
|
|
|
userGroupId: this.userGroupId,
|
2020-01-29 20:37:25 +01:00
|
|
|
withReplies: this.withReplies,
|
|
|
|
withFile: this.withFile,
|
|
|
|
notify: this.notify,
|
|
|
|
caseSensitive: this.caseSensitive,
|
|
|
|
users: this.users.trim().split('\n').map(x => x.trim()),
|
2020-02-20 16:28:45 +01:00
|
|
|
keywords: this.keywords.trim().split('\n').map(x => x.trim().split(' ')),
|
|
|
|
excludeKeywords: this.excludeKeywords.trim().split('\n').map(x => x.trim().split(' ')),
|
2020-01-29 20:37:25 +01:00
|
|
|
});
|
2021-08-07 10:55:16 +02:00
|
|
|
this.$emit('updated');
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
async deleteAntenna() {
|
2020-10-17 13:12:00 +02:00
|
|
|
const { canceled } = await os.dialog({
|
2020-01-29 20:37:25 +01:00
|
|
|
type: 'warning',
|
|
|
|
text: this.$t('removeAreYouSure', { x: this.antenna.name }),
|
|
|
|
showCancelButton: true
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
await os.api('antennas/delete', {
|
2020-01-29 20:37:25 +01:00
|
|
|
antennaId: this.antenna.id,
|
|
|
|
});
|
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
os.success();
|
2020-01-29 20:37:25 +01:00
|
|
|
this.$emit('deleted');
|
|
|
|
},
|
|
|
|
|
|
|
|
addUser() {
|
2020-10-17 13:12:00 +02:00
|
|
|
os.selectUser().then(user => {
|
2020-01-29 20:37:25 +01:00
|
|
|
this.users = this.users.trim();
|
|
|
|
this.users += '\n@' + getAcct(user);
|
|
|
|
this.users = this.users.trim();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.shaynizk {
|
2021-08-07 10:55:16 +02:00
|
|
|
> .form {
|
|
|
|
padding: 32px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .actions {
|
|
|
|
padding: 24px 32px;
|
|
|
|
border-top: solid 0.5px var(--divider);
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|