began implementing sharing dialog

This commit is contained in:
Stefan Zermatten
2020-03-02 16:31:57 +02:00
parent 724f9574a2
commit 5578dca6e9
4 changed files with 128 additions and 8 deletions

View File

@@ -9,7 +9,8 @@ let SharingSchema = new SimpleSchema({
readers: {
type: Array,
defaultValue: [],
index: 1
index: 1,
max: 50,
},
"readers.$": {
type: String,
@@ -18,7 +19,8 @@ let SharingSchema = new SimpleSchema({
writers: {
type: Array,
defaultValue: [],
index: 1
index: 1,
max: 20,
},
"writers.$": {
type: String,

View File

@@ -4,6 +4,8 @@ const userSchema = new SimpleSchema({
username: {
type: String,
optional: true,
max: 30,
min: 4,
},
emails: {
type: Array,
@@ -103,7 +105,7 @@ Meteor.users.sendVerificationEmail = new ValidatedMethod({
type: String,
},
}).validator(),
run(userId, address){
run({userId, address}){
userId = this.userId || userId;
let user = Meteor.users.findOne(userId);
if (!user) {
@@ -123,3 +125,17 @@ Meteor.users.isAdmin = function(userId){
let user = Meteor.users.findOne(userId);
return user && user.roles.includes('admin');
}
Meteor.users.findUserByUsernameOrEmail = new ValidatedMethod({
name: 'Users.methods.findUserByUsernameOrEmail',
validate: new SimpleSchema({
usernameOrEmail:{
type: String,
},
}).validator(),
run({usernameOrEmail}){
let user = Accounts.findUserByUsername(username) ||
Accounts.findUserByEmail(email);
return user && user._id;
}
});

View File

@@ -9,10 +9,12 @@ Meteor.publish("user", function(){
}});
});
Meteor.publish("userNames", function(ids){
Meteor.publish("userPublicProfiles", function(ids){
if (!this.userId || !ids) return [];
return Meteor.users.find(
{_id: {$in: ids}},
{fields: {username: 1}}
);
return Meteor.users.find({
_id: {$in: ids}
},{
fields: {username: 1},
sort: {username: 1},
});
});

View File

@@ -0,0 +1,100 @@
<template lang="html">
<dialog-base>
<div slot="toolbar">
Sharing {{name}}
</div>
<div>
<smart-select
label="Who can view"
:items="[
{text: 'Only people I share with', value: false},
{text: 'Anyone with link', value: true}
]"
:value="model.public"
:error-messages="errors.public"
@change="(value, ack) => setSheetPublic({value, ack}))"
/>
<div class="layout row">
<text-field
label="Username or email"
@change="(value, ack) => getUser({value, ack})"
:debounceTime="300"
/>
<v-btn :disabled="userFoundState !== found">
Share
</v-btn>
</div>
<div class="sharedWith">
<h3>Can Edit</h3>
<div v-for="userId in model.writers">
{{username(userId)}}
<v-btn flat icon>
<v-icon>delete</v-icon>
</v-btn>
</div>
<h3>Can View</h3>
<div v-for="userId in model.readers">
{{username(userId)}}
<v-btn flat icon>
<v-icon>delete</v-icon>
</v-btn>
</div>
</div>
</div>
</dialog-base>
</template>
<script>
import fetchDocByRef from '/imports/api/parenting/fetchDocByRef.js';
import DialogBase from '/imports/ui/dialogStack/DialogBase.vue';
export default {
components: {
DialogBase,
},
data(){
userFoundState: 'idle',
userId: undefined,
},
props: {
ref: Object,
},
methods: {
getUser({value, ack}){
Meteor.users.findUserByUsernameOrEmail.call({
usernameOrEmail: value
}, (error, result) => {
if (error) {
ack(error && error.reason || error);
this.userFoundState = 'failed';
} else {
this.userId = result;
if (result){
this.userFoundState = 'found';
ack();
} else {
this.userFoundState = 'notFound';
ack('User not found');
}
}
});
},
},
meteor: {
model: {
return fetchDocByRef(this.ref);
},
username(userId){
let user = Meteor.users.findOne(userId);
return user && user.username;
},
$subscribe: {
'userPublicProfiles'(){
return [...this.model.writers, ...this.model.readers];
},
},
},
}
</script>
<style lang="css" scoped>
</style>