From 73a84002d168c40a61abf8590a56131f69c68ad4 Mon Sep 17 00:00:00 2001 From: Tomas 'Jethro' Pokorny <xtompok@gmail.com> Date: Tue, 3 Nov 2020 20:27:20 +0100 Subject: [PATCH 1/2] treenode | fix CSRF token and saving text. --- seminar/views/views_rest.py | 1 + vue_frontend/src/components/TextNode.vue | 1 + 2 files changed, 2 insertions(+) diff --git a/seminar/views/views_rest.py b/seminar/views/views_rest.py index 8bf7d040..aa3fca55 100644 --- a/seminar/views/views_rest.py +++ b/seminar/views/views_rest.py @@ -74,6 +74,7 @@ class TextNodeWriteSerializer(serializers.ModelSerializer): def update(self,node,validated_data): node.text.na_web = validated_data.get('text').get('na_web') + node.text.save() return node class Meta: diff --git a/vue_frontend/src/components/TextNode.vue b/vue_frontend/src/components/TextNode.vue index cd0fda64..f6e81fcc 100644 --- a/vue_frontend/src/components/TextNode.vue +++ b/vue_frontend/src/components/TextNode.vue @@ -88,6 +88,7 @@ export default { mounted: function() { //console.log("mounted"); this.editorConfig.simpleUpload.headers['X-CSRFToken'] = this.getCookie('csrftoken'); + axios.defaults.headers.common['X-CSRFToken'] = this.getCookie('csrftoken'); if (this.create){ this.currentText = ""; this.originalText = ""; From 1ba52cb397204b7b559f64225260d06eea1d5dea Mon Sep 17 00:00:00 2001 From: Tomas 'Jethro' Pokorny <xtompok@gmail.com> Date: Tue, 3 Nov 2020 21:09:33 +0100 Subject: [PATCH 2/2] treenode | Added editMode and debugMode properties. --- vue_frontend/src/components/TextNode.vue | 15 +++++------ vue_frontend/src/components/TreeNode.vue | 26 ++++++++++++++------ vue_frontend/src/components/TreeNodeRoot.vue | 14 ++++++++--- 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/vue_frontend/src/components/TextNode.vue b/vue_frontend/src/components/TextNode.vue index f6e81fcc..aaa02fdb 100644 --- a/vue_frontend/src/components/TextNode.vue +++ b/vue_frontend/src/components/TextNode.vue @@ -10,22 +10,20 @@ <textarea id="textarea" v-model="currentText" rows="8" cols="50"></textarea> <br> <button v-on:click="plainEditShow=!plainEditShow">Editovat v editoru</button> - <button v-on:click="saveText">Uložit</button> - <button v-on:click="currentText = originalText;editorShow=!editorShow;">Zahodit úpravy</button> </div> <div v-else> <component v-bind:is="editorComponent" :editor="editor" v-model="currentText" :config="editorConfig"></component> <button v-on:click="plainEditShow=!plainEditShow">Editovat HTML</button> - <button v-on:click="saveText">Uložit</button> - <button v-on:click="currentText = originalText;editorShow=!editorShow;">Zahodit úpravy</button> - <div> + </div> + <button v-on:click="saveText">Uložit</button> + <button v-on:click="currentText = originalText;editorShow=!editorShow;">Zahodit úpravy</button> </template> <template v-else v-bind:class="changedObject"> <p v-html="currentText"></p> - <button v-on:click="editorShow=!editorShow">Upravit</button> + <button v-if="editorMode" v-on:click="editorShow=!editorShow">Upravit</button> </template> </div> </template> @@ -47,9 +45,7 @@ export default { extraPlugins: ['SimpleUploadAdapter'], simpleUpload: { uploadUrl: "/temp/image_upload/", - headers: { - "test":"testh" - }, + headers: {}, withCredentials: true } // The configuration of the editor. @@ -81,6 +77,7 @@ export default { props: { item: Object, editorShow: Boolean, + editorMode: Boolean, create: Boolean, where: String, refnode: Object diff --git a/vue_frontend/src/components/TreeNode.vue b/vue_frontend/src/components/TreeNode.vue index 196f899d..6626f699 100644 --- a/vue_frontend/src/components/TreeNode.vue +++ b/vue_frontend/src/components/TreeNode.vue @@ -4,10 +4,12 @@ <!--b v-if="v_tematu">v tematu</b> <b v-if="visible">visible</b> Force visible: {{String(force_visible)}}--> - <component :is='item.node.polymorphic_ctype.model' :item='item' :key='item.node.id'></component> + <component :is='item.node.polymorphic_ctype.model' :item='item' :key='item.node.id' + :editorMode="editorMode" + :debugMode="debugMode"></component> - <button v-on:click="debugShow = !debugShow" class="nodebug">Ladící data</button> <!-- bude tu nějaký if na class="nodebug", v debug módu bude tlačítko vidět, jinak ne --> + <button v-if="debugMode" v-on:click="debugShow = !debugShow" class="nodebug">Ladící data</button> <!-- bude tu nějaký if na class="nodebug", v debug módu bude tlačítko vidět, jinak ne --> <div v-if="debugShow"> <pre>{{ item.node.polymorphic_ctype.model }}</pre> <pre>{{ item }}</pre> @@ -33,12 +35,16 @@ <div v-if="chld.node.polymorphic_ctype.model==='ulohazadaninode'"> <button v-on:click="showChildren=!showChildren"> Tady možná něco je </button> <TreeNode :item="chld" :v_tematu="true" - :force_visible="showChildren"> + :force_visible="showChildren" + :editorMode="editorMode" + :debugMode="debugMode"> </TreeNode> </div> <div v-else> <TreeNode :item="chld" :v_tematu="true" - :force_visible="showChildren"> + :force_visible="showChildren" + :editorMode="editorMode" + :debugMode="debugMode"> </TreeNode> </div> <div v-if="chld.appendable_siblings.length > 0" class="mam-org-only" > @@ -55,12 +61,16 @@ <div v-if="v_tematu && chld.node.polymorphic_ctype.model==='ulohazadaninode'"> <div> Tady možná něco je </div> <TreeNode :item="chld" :v_tematu="v_tematu" - :force_visible="force_visible"> + :force_visible="force_visible" + :editorMode="editorMode" + :debugMode="debugMode"> </TreeNode> </div> <div v-else> <TreeNode :item="chld" :v_tematu="v_tematu" - :force_visible="force_visible"> + :force_visible="force_visible" + :editorMode="editorMode" + :debugMode="debugMode"> </TreeNode> </div> <div v-if="chld.appendable_siblings.length > 0" class="mam-org-only" > @@ -107,7 +117,9 @@ export default { props: { item: Object, force_visible: Boolean, - v_tematu: Boolean + v_tematu: Boolean, + editorMode: Boolean, + debugMode: Boolean, }, methods: { hideNode: function(chld){ diff --git a/vue_frontend/src/components/TreeNodeRoot.vue b/vue_frontend/src/components/TreeNodeRoot.vue index fd70a028..e62a85b4 100644 --- a/vue_frontend/src/components/TreeNodeRoot.vue +++ b/vue_frontend/src/components/TreeNodeRoot.vue @@ -6,7 +6,11 @@ <!--pre> {{item}} </pre--> - <TreeNode :item="item"/> + <button v-show="editorMode" v-on:click="editorMode = false">Vypnout editační mód</button> + <button v-show="!editorMode" v-on:click="editorMode = true">Zapnout editační mód</button> + <button v-show="debugMode" v-on:click="debugMode = false">Vypnout ladicí mód</button> + <button v-show="!debugMode" v-on:click="debugMode = true">Zapnout ladicí mód</button> + <TreeNode :item="item" :editorMode="editorMode" :debugMode="debugMode"/> </div> </template> @@ -21,10 +25,14 @@ export default { data: () => ({ loading: true, item: null, - tnid: 1 + tnid: 1, + editorMode: false, + debugMode: false, }), props:{ - tnid: Number + tnid: Number, + editorMode: Boolean, + debugMode: Boolean, }, mounted: function() { this.getArticles();