Added "duplicate" option to library properties

This commit is contained in:
Thaum Rystra
2020-05-25 17:23:36 +02:00
parent e9c643699c
commit add0cac31d
3 changed files with 48 additions and 3 deletions

View File

@@ -52,11 +52,28 @@ const insertNode = new ValidatedMethod({
name: 'LibraryNodes.methods.insert',
validate: null,
run(libraryNode) {
delete libraryNode._id;
assertNodeEditPermission(libraryNode, this.userId);
return LibraryNodes.insert(libraryNode);
},
});
const duplicateNode = new ValidatedMethod({
name: 'LibraryNodes.methods.duplicate',
validate: new SimpleSchema({
_id: {
type: String,
regEx: SimpleSchema.RegEx.Id,
}
}).validator(),
run({_id}) {
let libraryNode = LibraryNodes.findOne(_id);
assertNodeEditPermission(libraryNode, this.userId);
delete libraryNode._id;
return LibraryNodes.insert(libraryNode);
},
})
const updateLibraryNode = new ValidatedMethod({
name: 'LibraryNodes.methods.update',
validate({_id, path}){
@@ -132,6 +149,7 @@ export default LibraryNodes;
export {
LibraryNodeSchema,
insertNode,
duplicateNode,
updateLibraryNode,
pullFromLibraryNode,
pushToLibraryNode,

View File

@@ -39,10 +39,25 @@
</v-btn>
</template>
<v-list>
<v-list-tile @click="$emit('duplicate')">
<v-list-tile-content>
<v-list-tile-title>
Duplicate
</v-list-tile-title>
</v-list-tile-content>
<v-list-tile-action>
<v-icon>file_copy</v-icon>
</v-list-tile-action>
</v-list-tile>
<v-list-tile @click="$emit('remove')">
<v-list-tile-title>
Delete <v-icon>delete</v-icon>
</v-list-tile-title>
<v-list-tile-content>
<v-list-tile-title>
Delete
</v-list-tile-title>
</v-list-tile-content>
<v-list-tile-action>
<v-icon>delete</v-icon>
</v-list-tile-action>
</v-list-tile>
</v-list>
</v-menu>

View File

@@ -5,6 +5,7 @@
:model="model"
:editing="editing"
:flat="flat"
@duplicate="duplicate"
@remove="remove"
@toggle-editing="editing = !editing"
@color-changed="value => change({path: ['color'], value})"
@@ -47,6 +48,7 @@
<script>
import LibraryNodes, {
duplicateNode,
updateLibraryNode,
pushToLibraryNode,
pullFromLibraryNode,
@@ -106,6 +108,16 @@
},
methods: {
getPropertyName,
duplicate(){
duplicateNode.call({_id: this._id}, (error) => {
console.error(error);
if (this.embedded){
this.$emit('duplicated');
} else {
this.$store.dispatch('popDialogStack');
}
});
},
change({path, value, ack}){
updateLibraryNode.call({_id: this._id, path, value}, (error) =>{
if (ack){