diff --git a/mamweb/routers.py b/mamweb/routers.py index ee310427..f2a172cb 100644 --- a/mamweb/routers.py +++ b/mamweb/routers.py @@ -3,7 +3,8 @@ from seminar import viewsets as vs router = routers.DefaultRouter() -router.register(r'ulohavzoraknode', vs.UlohaVzorakNodeViewSet) +router.register(r'ulohavzoraknode', vs.UlohaVzorakNodeViewSet,basename='ulohavzoraknode') router.register(r'text', vs.TextViewSet) router.register(r'textnode', vs.TextNodeViewSet) +router.register(r'castnode', vs.CastNodeViewSet) diff --git a/seminar/views/views_rest.py b/seminar/views/views_rest.py index 8cee4fd1..8bf7d040 100644 --- a/seminar/views/views_rest.py +++ b/seminar/views/views_rest.py @@ -92,7 +92,12 @@ class TextNodeCreateSerializer(serializers.ModelSerializer): refnode_id = validated_data.pop('refnode') refnode = m.TreeNode.objects.get(pk=refnode_id) text = m.Text.objects.create(**temp_text) - node = treelib.create_child(refnode,m.TextNode,text=text) + if where == 'syn': + node = treelib.create_child(refnode,m.TextNode,text=text) + elif where == 'za': + node = treelib.create_node_after(refnode,m.TextNode,text=text) + elif where == 'pred': + node = treelib.create_node_before(refnode,m.TextNode,text=text) node.where = None node.refnode = None return node @@ -108,6 +113,30 @@ class CastNodeSerializer(serializers.ModelSerializer): fields = '__all__' depth = DEFAULT_NODE_DEPTH +class CastNodeCreateSerializer(serializers.ModelSerializer): + refnode = serializers.CharField() + where = serializers.CharField() + + def create(self,validated_data): + temp_nadpis = validated_data.pop('nadpis') + where = validated_data.pop('where') + refnode_id = validated_data.pop('refnode') + refnode = m.TreeNode.objects.get(pk=refnode_id) + if where == 'syn': + node = treelib.create_child(refnode,m.CastNode,nadpis=temp_nadpis) + elif where == 'za': + node = treelib.create_node_after(refnode,m.CastNode,nadpis=temp_nadpis) + elif where == 'pred': + node = treelib.create_node_before(refnode,m.CastNode,nadpis=temp_nadpis) + node.where = None + node.refnode = None + return node + + class Meta: + model = m.CastNode + fields = ('nadpis','where','refnode') + depth = DEFAULT_NODE_DEPTH + class ReseniNodeSerializer(serializers.ModelSerializer): class Meta: model = m.ReseniNode diff --git a/seminar/viewsets.py b/seminar/viewsets.py index a0c0750d..8c83c067 100644 --- a/seminar/viewsets.py +++ b/seminar/viewsets.py @@ -58,3 +58,20 @@ class TextNodeViewSet(ReadWriteSerializerMixin,viewsets.ModelViewSet): queryset = m.TextNode.objects.all() read_serializer_class = views.TextNodeSerializer write_serializer_class = views.TextNodeWriteSerializer + create_serializer_class = views.TextNodeCreateSerializer + +class CastNodeViewSet(ReadWriteSerializerMixin,viewsets.ModelViewSet): + queryset = m.CastNode.objects.all() + read_serializer_class = views.CastNodeSerializer + write_serializer_class = views.CastNodeSerializer + create_serializer_class = views.CastNodeCreateSerializer + +class UlohaVzorakNodeViewSet(viewsets.ModelViewSet): + serializer_class = views.UlohaVzorakNodeSerializer + + def get_queryset(self): + queryset = m.UlohaVzorakNode.objects.all() + nazev = self.request.query_params.get('nazev',None) + if nazev is not None: + queryset = queryset.filter(nazev__contains=nazev) + return queryset diff --git a/vue_frontend/src/App.vue b/vue_frontend/src/App.vue index a4f3aea3..d532ef0c 100644 --- a/vue_frontend/src/App.vue +++ b/vue_frontend/src/App.vue @@ -1,8 +1,8 @@ diff --git a/vue_frontend/src/components/TextNode.vue b/vue_frontend/src/components/TextNode.vue index ce45f293..3bcb4f02 100644 --- a/vue_frontend/src/components/TextNode.vue +++ b/vue_frontend/src/components/TextNode.vue @@ -6,7 +6,7 @@
- +
@@ -67,21 +67,21 @@ export default { }, methods: { getText: function() { - this.loading = true; - console.log(this.item); - console.log(this.item.node.text); - axios.get('/treenode/text/'+this.item.node.text) - .then((response) => { - this.text = response.data.na_web; - this.loading = false; - }) - .catch((err) => { - this.loading = false; - console.log(err); + this.loading = true; + console.log(this.item); + console.log(this.item.node.text); + axios.get('/treenode/text/'+this.item.node.text) + .then((response) => { + this.text = response.data.na_web; + this.loading = false; }) + .catch((err) => { + this.loading = false; + console.log(err); + }) }, - updateText: function() { + saveText: function() { console.log("Saving text"); console.log(this.currentText); if (this.create){ @@ -91,7 +91,11 @@ export default { 'text': { 'na_web': this.currentText}, 'refnode': this.refnode.id, 'where': this.where - }).then(response => {this.originalText = response.data.text.na_web}) + }).then(response => { + this.originalText = response.data.text.na_web; + this.loading = false; + this.$root.$emit('updateData',"textNode create update"); + }) .catch(e => { this.errors.push(e) }); @@ -99,24 +103,16 @@ export default { axios.put('/api/textnode/'+this.item.node.id+'/',{ 'text': { 'na_web': this.currentText}, 'id': this.item.node.id - }).then(response => {this.originalText = response.data.text.na_web}) + }).then(response => { + this.originalText = response.data.text.na_web; + }) .catch(e => { this.errors.push(e) }); } - - // FIXME really save! this.editorShow = false; }, - save: function() { - console.log(this.item); - if (this.create){ - console.log(this.refnode); - console.log(this.where); - } - - } } } diff --git a/vue_frontend/src/components/TreeNode.vue b/vue_frontend/src/components/TreeNode.vue index 8da318d6..1b361614 100644 --- a/vue_frontend/src/components/TreeNode.vue +++ b/vue_frontend/src/components/TreeNode.vue @@ -5,29 +5,31 @@
{{ item.node.polymorphic_ctype.model }}
{{ item }}
- +
Vložit jako syna
-
- Vložit před - -
+
+
+ Vložit před + +
- + +
@@ -85,4 +87,9 @@ a { border-color: "black"; margin: 5px; } +.children { + border: 1px solid; + border-color: #ff0000; + margin: 5px; +} diff --git a/vue_frontend/src/components/UlohaVzorakNode.vue b/vue_frontend/src/components/UlohaVzorakNode.vue index 398b3924..382adce2 100644 --- a/vue_frontend/src/components/UlohaVzorakNode.vue +++ b/vue_frontend/src/components/UlohaVzorakNode.vue @@ -1,22 +1,68 @@ diff --git a/vue_frontend/src/components/UlohaZadaniNode.vue b/vue_frontend/src/components/UlohaZadaniNode.vue index eb4806b1..7c5f6346 100644 --- a/vue_frontend/src/components/UlohaZadaniNode.vue +++ b/vue_frontend/src/components/UlohaZadaniNode.vue @@ -1,7 +1,7 @@