2020-01-29 20:37:25 +01:00
|
|
|
<template>
|
|
|
|
<div class="mk-list-page">
|
2020-02-08 07:11:12 +01:00
|
|
|
<portal to="icon"><fa :icon="faListUl"/></portal>
|
|
|
|
<portal to="title">{{ list.name }}</portal>
|
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
<transition name="zoom" mode="out-in">
|
2020-02-08 07:11:12 +01:00
|
|
|
<div v-if="list" class="_card">
|
|
|
|
<div class="_content">
|
|
|
|
<mk-button inline @click="renameList()">{{ $t('rename') }}</mk-button>
|
|
|
|
<mk-button inline @click="deleteList()">{{ $t('delete') }}</mk-button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</transition>
|
|
|
|
|
|
|
|
<transition name="zoom" mode="out-in">
|
|
|
|
<div v-if="list" class="_card members">
|
|
|
|
<div class="_title">{{ $t('members') }}</div>
|
2020-01-29 20:37:25 +01:00
|
|
|
<div class="_content">
|
|
|
|
<div class="users">
|
2020-02-08 07:11:12 +01:00
|
|
|
<div class="user" v-for="user in users" :key="user.id">
|
2020-01-29 20:37:25 +01:00
|
|
|
<mk-avatar :user="user" class="avatar"/>
|
|
|
|
<div class="body">
|
|
|
|
<mk-user-name :user="user" class="name"/>
|
|
|
|
<mk-acct :user="user" class="acct"/>
|
|
|
|
</div>
|
|
|
|
<div class="action">
|
|
|
|
<button class="_button" @click="removeUser(user)"><fa :icon="faTimes"/></button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="_footer">
|
2020-02-08 07:11:12 +01:00
|
|
|
<mk-button inline @click="addUser()">{{ $t('addUser') }}</mk-button>
|
2020-01-29 20:37:25 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</transition>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
2020-02-08 07:11:12 +01:00
|
|
|
import { faTimes, faListUl } from '@fortawesome/free-solid-svg-icons';
|
2020-01-29 20:37:25 +01:00
|
|
|
import i18n from '../../i18n';
|
|
|
|
import Progress from '../../scripts/loading';
|
|
|
|
import MkButton from '../../components/ui/button.vue';
|
2020-02-08 07:11:12 +01:00
|
|
|
import MkUserSelect from '../../components/user-select.vue';
|
2020-01-29 20:37:25 +01:00
|
|
|
|
|
|
|
export default Vue.extend({
|
|
|
|
i18n,
|
|
|
|
|
|
|
|
metaInfo() {
|
|
|
|
return {
|
|
|
|
title: this.list ? `${this.list.name} | ${this.$t('manageLists')}` : this.$t('manageLists')
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
components: {
|
|
|
|
MkButton
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
list: null,
|
|
|
|
users: [],
|
2020-02-08 07:11:12 +01:00
|
|
|
faTimes, faListUl
|
2020-01-29 20:37:25 +01:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
$route: 'fetch'
|
|
|
|
},
|
|
|
|
|
|
|
|
created() {
|
|
|
|
this.fetch();
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
fetch() {
|
|
|
|
Progress.start();
|
|
|
|
this.$root.api('users/lists/show', {
|
|
|
|
listId: this.$route.params.list
|
|
|
|
}).then(list => {
|
|
|
|
this.list = list;
|
|
|
|
this.$root.api('users/show', {
|
|
|
|
userIds: this.list.userIds
|
|
|
|
}).then(users => {
|
|
|
|
this.users = users;
|
|
|
|
Progress.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-02-08 07:11:12 +01:00
|
|
|
addUser() {
|
|
|
|
this.$root.new(MkUserSelect, {}).$once('selected', user => {
|
|
|
|
this.$root.api('users/lists/push', {
|
|
|
|
listId: this.list.id,
|
|
|
|
userId: user.id
|
|
|
|
}).then(() => {
|
|
|
|
this.users.push(user);
|
|
|
|
this.$root.dialog({
|
|
|
|
type: 'success',
|
|
|
|
iconOnly: true, autoClose: true
|
|
|
|
});
|
|
|
|
}).catch(e => {
|
|
|
|
this.$root.dialog({
|
|
|
|
type: 'error',
|
|
|
|
text: e
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
removeUser(user) {
|
|
|
|
this.$root.api('users/lists/pull', {
|
|
|
|
listId: this.list.id,
|
|
|
|
userId: user.id
|
|
|
|
}).then(() => {
|
|
|
|
this.users = this.users.filter(x => x.id !== user.id);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
async renameList() {
|
|
|
|
const { canceled, result: name } = await this.$root.dialog({
|
|
|
|
title: this.$t('enterListName'),
|
|
|
|
input: {
|
|
|
|
default: this.list.name
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
|
|
|
await this.$root.api('users/lists/update', {
|
|
|
|
listId: this.list.id,
|
|
|
|
name: name
|
|
|
|
});
|
|
|
|
|
|
|
|
this.list.name = name;
|
|
|
|
},
|
|
|
|
|
|
|
|
async deleteList() {
|
|
|
|
const { canceled } = await this.$root.dialog({
|
|
|
|
type: 'warning',
|
2020-02-08 07:11:12 +01:00
|
|
|
text: this.$t('removeAreYouSure', { x: this.list.name }),
|
2020-01-29 20:37:25 +01:00
|
|
|
showCancelButton: true
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
|
|
|
await this.$root.api('users/lists/delete', {
|
|
|
|
listId: this.list.id
|
|
|
|
});
|
|
|
|
this.$root.dialog({
|
|
|
|
type: 'success',
|
|
|
|
iconOnly: true, autoClose: true
|
|
|
|
});
|
|
|
|
this.$router.push('/my/lists');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.mk-list-page {
|
2020-02-08 07:11:12 +01:00
|
|
|
> .members {
|
2020-01-29 20:37:25 +01:00
|
|
|
> ._content {
|
|
|
|
max-height: 400px;
|
|
|
|
overflow: auto;
|
|
|
|
|
|
|
|
> .users {
|
|
|
|
> .user {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
> .avatar {
|
|
|
|
width: 50px;
|
|
|
|
height: 50px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .body {
|
|
|
|
flex: 1;
|
|
|
|
padding: 8px;
|
|
|
|
|
|
|
|
> .name {
|
|
|
|
display: block;
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .acct {
|
|
|
|
opacity: 0.5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|