Add duplicate action to frontend
This commit is contained in:
parent
6be6ab8092
commit
4693d2c01a
|
|
@ -61,6 +61,14 @@ describe('Custom Content Block', () => {
|
||||||
cy.log('Opening More Menu');
|
cy.log('Opening More Menu');
|
||||||
cy.getByDataCy('more-options-link').click();
|
cy.getByDataCy('more-options-link').click();
|
||||||
|
|
||||||
|
cy.log('Duplicating Content Block');
|
||||||
|
cy.getByDataCy('duplicate-content-block-link').click();
|
||||||
|
|
||||||
|
cy.get('.content-block').should('have.length', 2);
|
||||||
|
|
||||||
|
cy.log('Opening More Menu');
|
||||||
|
cy.getByDataCy('more-options-link').click();
|
||||||
|
|
||||||
// check if content block is still there
|
// check if content block is still there
|
||||||
cy.log('Deleting Content Block');
|
cy.log('Deleting Content Block');
|
||||||
cy.getByDataCy('delete-content-block-link').click();
|
cy.getByDataCy('delete-content-block-link').click();
|
||||||
|
|
|
||||||
|
|
@ -11,14 +11,27 @@
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="block-actions"
|
class="block-actions"
|
||||||
v-if="canEditContentBlock && editMode"
|
v-if="canEditModule"
|
||||||
>
|
>
|
||||||
<user-widget
|
<user-widget
|
||||||
v-bind="me"
|
v-bind="me"
|
||||||
class="block-actions__user-widget content-block__user-widget"
|
class="block-actions__user-widget content-block__user-widget"
|
||||||
|
v-if="isMine"
|
||||||
/>
|
/>
|
||||||
<more-options-widget>
|
<more-options-widget>
|
||||||
<li class="popover-links__link">
|
<li
|
||||||
|
class="popover-links__link"
|
||||||
|
>
|
||||||
|
<popover-link
|
||||||
|
data-cy="duplicate-content-block-link"
|
||||||
|
text="Duplizieren"
|
||||||
|
@link-action="duplicateContentBlock(contentBlock)"
|
||||||
|
/>
|
||||||
|
</li>
|
||||||
|
<li
|
||||||
|
class="popover-links__link"
|
||||||
|
v-if="isMine"
|
||||||
|
>
|
||||||
<popover-link
|
<popover-link
|
||||||
data-cy="delete-content-block-link"
|
data-cy="delete-content-block-link"
|
||||||
text="Löschen"
|
text="Löschen"
|
||||||
|
|
@ -26,7 +39,10 @@
|
||||||
/>
|
/>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li class="popover-links__link">
|
<li
|
||||||
|
class="popover-links__link"
|
||||||
|
v-if="isMine"
|
||||||
|
>
|
||||||
<popover-link
|
<popover-link
|
||||||
text="Bearbeiten"
|
text="Bearbeiten"
|
||||||
@link-action="editContentBlock(contentBlock)"
|
@link-action="editContentBlock(contentBlock)"
|
||||||
|
|
@ -83,13 +99,14 @@
|
||||||
|
|
||||||
import CHAPTER_QUERY from '@/graphql/gql/queries/chapterQuery.gql';
|
import CHAPTER_QUERY from '@/graphql/gql/queries/chapterQuery.gql';
|
||||||
import DELETE_CONTENT_BLOCK_MUTATION from '@/graphql/gql/mutations/deleteContentBlock.gql';
|
import DELETE_CONTENT_BLOCK_MUTATION from '@/graphql/gql/mutations/deleteContentBlock.gql';
|
||||||
|
import DUPLICATE_CONTENT_BLOCK_MUTATION from '@/graphql/gql/mutations/duplicateContentBlock.gql';
|
||||||
|
|
||||||
import me from '@/mixins/me';
|
import me from '@/mixins/me';
|
||||||
|
|
||||||
import {hidden} from '@/helpers/visibility';
|
import {hidden} from '@/helpers/visibility';
|
||||||
import {CONTENT_TYPE} from '@/consts/types';
|
import {CONTENT_TYPE} from '@/consts/types';
|
||||||
import PopoverLink from '@/components/ui/PopoverLink';
|
import PopoverLink from '@/components/ui/PopoverLink';
|
||||||
import {removeAtIndex} from '@/graphql/immutable-operations';
|
import {insertAtIndex, removeAtIndex} from '@/graphql/immutable-operations';
|
||||||
import {EDIT_CONTENT_BLOCK_PAGE} from '@/router/module.names';
|
import {EDIT_CONTENT_BLOCK_PAGE} from '@/router/module.names';
|
||||||
import {instrumentCategory} from '@/helpers/instrumentType';
|
import {instrumentCategory} from '@/helpers/instrumentType';
|
||||||
|
|
||||||
|
|
@ -163,7 +180,10 @@
|
||||||
return {};
|
return {};
|
||||||
},
|
},
|
||||||
canEditContentBlock() {
|
canEditContentBlock() {
|
||||||
return this.contentBlock.mine && !this.contentBlock.indent;
|
return this.isMine && !this.contentBlock.indent;
|
||||||
|
},
|
||||||
|
isMine() {
|
||||||
|
return this.contentBlock.mine;
|
||||||
},
|
},
|
||||||
contentBlocksWithContentLists() {
|
contentBlocksWithContentLists() {
|
||||||
/*
|
/*
|
||||||
|
|
@ -218,6 +238,36 @@
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
duplicateContentBlock({id}) {
|
||||||
|
const parent = this.parent;
|
||||||
|
this.$apollo.mutate({
|
||||||
|
mutation: DUPLICATE_CONTENT_BLOCK_MUTATION,
|
||||||
|
variables: {
|
||||||
|
input: {
|
||||||
|
id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
update(store, {data: {duplicateContentBlock: {contentBlock}}}) {
|
||||||
|
if (contentBlock) {
|
||||||
|
const query = CHAPTER_QUERY;
|
||||||
|
const variables = {
|
||||||
|
id: parent.id,
|
||||||
|
};
|
||||||
|
const {chapter} = store.readQuery({query, variables});
|
||||||
|
const index = chapter.contentBlocks.findIndex(contentBlock => contentBlock.id === id);
|
||||||
|
const contentBlocks = insertAtIndex(chapter.contentBlocks, index, contentBlock);
|
||||||
|
const data = {
|
||||||
|
chapter: {
|
||||||
|
...chapter,
|
||||||
|
contentBlocks,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
store.writeQuery({query, variables, data});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
},
|
||||||
editContentBlock(contentBlock) {
|
editContentBlock(contentBlock) {
|
||||||
const route = {
|
const route = {
|
||||||
name: EDIT_CONTENT_BLOCK_PAGE,
|
name: EDIT_CONTENT_BLOCK_PAGE,
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
#import "../fragments/contentBlockInterfaceParts.gql"
|
||||||
|
#import "../fragments/contentBlockParts.gql"
|
||||||
|
|
||||||
|
mutation DuplicateContentBlock($input: DuplicateContentBlockInput!) {
|
||||||
|
duplicateContentBlock(input: $input) {
|
||||||
|
contentBlock {
|
||||||
|
...ContentBlockInterfaceParts
|
||||||
|
...ContentBlockParts
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -15,7 +15,7 @@ class ContentBlockManager(PageManager):
|
||||||
user_created=True,
|
user_created=True,
|
||||||
owner=user,
|
owner=user,
|
||||||
contents=content_block.contents,
|
contents=content_block.contents,
|
||||||
title=content_block.title,
|
title=f'{content_block.title} (Kopie)',
|
||||||
type=content_block.type,
|
type=content_block.type,
|
||||||
)
|
)
|
||||||
content_block.add_sibling(instance=new_content_block, pos='right')
|
content_block.add_sibling(instance=new_content_block, pos='right')
|
||||||
|
|
|
||||||
|
|
@ -478,6 +478,16 @@ type DjangoDebugSQL {
|
||||||
encoding: String
|
encoding: String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input DuplicateContentBlockInput {
|
||||||
|
id: ID!
|
||||||
|
clientMutationId: String
|
||||||
|
}
|
||||||
|
|
||||||
|
type DuplicateContentBlockPayload {
|
||||||
|
contentBlock: ContentBlockNode
|
||||||
|
clientMutationId: String
|
||||||
|
}
|
||||||
|
|
||||||
type DuplicateName {
|
type DuplicateName {
|
||||||
reason: String
|
reason: String
|
||||||
}
|
}
|
||||||
|
|
@ -694,6 +704,7 @@ type Mutation {
|
||||||
mutateContentBlock(input: MutateContentBlockInput!): MutateContentBlockPayload
|
mutateContentBlock(input: MutateContentBlockInput!): MutateContentBlockPayload
|
||||||
addContentBlock(input: AddContentBlockInput!): AddContentBlockPayload
|
addContentBlock(input: AddContentBlockInput!): AddContentBlockPayload
|
||||||
deleteContentBlock(input: DeleteContentBlockInput!): DeleteContentBlockPayload
|
deleteContentBlock(input: DeleteContentBlockInput!): DeleteContentBlockPayload
|
||||||
|
duplicateContentBlock(input: DuplicateContentBlockInput!): DuplicateContentBlockPayload
|
||||||
updateSolutionVisibility(input: UpdateSolutionVisibilityInput!): UpdateSolutionVisibilityPayload
|
updateSolutionVisibility(input: UpdateSolutionVisibilityInput!): UpdateSolutionVisibilityPayload
|
||||||
updateLastModule(input: UpdateLastModuleInput!): UpdateLastModulePayload
|
updateLastModule(input: UpdateLastModuleInput!): UpdateLastModulePayload
|
||||||
updateLastTopic(input: UpdateLastTopicInput!): UpdateLastTopicPayload
|
updateLastTopic(input: UpdateLastTopicInput!): UpdateLastTopicPayload
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue