Treenode Editor | pridano mazani textnode a castnode.
Priprava na autocomplete problemu, zatim pouze cast API.
This commit is contained in:
parent
e3bb6dac2a
commit
514eddcf01
9 changed files with 86 additions and 8 deletions
|
@ -7,4 +7,5 @@ router.register(r'ulohavzoraknode', vs.UlohaVzorakNodeViewSet,basename='ulohavzo
|
|||
router.register(r'text', vs.TextViewSet)
|
||||
router.register(r'textnode', vs.TextNodeViewSet)
|
||||
router.register(r'castnode', vs.CastNodeViewSet)
|
||||
router.register(r'problem', vs.ProblemViewSet, basename='problem')
|
||||
|
||||
|
|
19
seminar/migrations/0090_auto_20201110_1958.py
Normal file
19
seminar/migrations/0090_auto_20201110_1958.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
# Generated by Django 2.2.12 on 2020-11-10 18:58
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('seminar', '0089_cislo_datum_preddeadline'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='textnode',
|
||||
name='text',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='seminar.Text', verbose_name='text'),
|
||||
),
|
||||
]
|
|
@ -1475,7 +1475,7 @@ class TextNode(TreeNode):
|
|||
verbose_name = 'Text (Node)'
|
||||
verbose_name_plural = 'Text (Node)'
|
||||
text = models.ForeignKey(Text,
|
||||
on_delete=models.PROTECT,
|
||||
on_delete=models.CASCADE,
|
||||
verbose_name = 'text')
|
||||
|
||||
def aktualizuj_nazev(self):
|
||||
|
|
|
@ -11,7 +11,10 @@ class TextSerializer(serializers.ModelSerializer):
|
|||
model = m.Text
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class ProblemSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = m.Problem
|
||||
fields = '__all__'
|
||||
|
||||
class UlohaVzorakNodeSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
from rest_framework import viewsets,filters
|
||||
from rest_framework import status
|
||||
from rest_framework.response import Response
|
||||
from django.core.exceptions import PermissionDenied
|
||||
|
||||
from . import models as m
|
||||
from . import views
|
||||
|
||||
|
@ -66,6 +70,14 @@ class CastNodeViewSet(ReadWriteSerializerMixin,viewsets.ModelViewSet):
|
|||
write_serializer_class = views.CastNodeSerializer
|
||||
create_serializer_class = views.CastNodeCreateSerializer
|
||||
|
||||
def destroy(self, request, *args, **kwargs):
|
||||
obj = self.get_object()
|
||||
print(obj)
|
||||
if obj.first_child is None:
|
||||
return super().destroy(request,*args,**kwargs)
|
||||
raise PermissionDenied('Nelze smazat CastNode, který má děti!')
|
||||
|
||||
|
||||
class UlohaVzorakNodeViewSet(viewsets.ModelViewSet):
|
||||
serializer_class = views.UlohaVzorakNodeSerializer
|
||||
|
||||
|
@ -75,3 +87,10 @@ class UlohaVzorakNodeViewSet(viewsets.ModelViewSet):
|
|||
if nazev is not None:
|
||||
queryset = queryset.filter(nazev__contains=nazev)
|
||||
return queryset
|
||||
|
||||
class ProblemViewSet(viewsets.ModelViewSet):
|
||||
serializer_class = views.ProblemSerializer
|
||||
|
||||
def get_queryset(self):
|
||||
queryset = m.Problem.objects.all()
|
||||
return queryset
|
||||
|
|
|
@ -7,7 +7,9 @@
|
|||
<button v-on:click="currentText = originalText;editorShow=!editorShow;">Zahodit úpravy</button>
|
||||
</div>
|
||||
<div v-else>
|
||||
<h4>{{ currentText }} </h4> <button v-if="editorMode" v-on:click="editorShow=!editorShow">Upravit</button>
|
||||
<h4>{{ currentText }} </h4>
|
||||
<button v-if="editorMode" v-on:click="editorShow = !editorShow">Upravit</button>
|
||||
<button v-if="editorMode" v-on:click="deleteCast" class="delete">Smazat</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
@ -25,6 +27,7 @@ export default {
|
|||
props: {
|
||||
item: Object,
|
||||
editorShow: Boolean,
|
||||
editorMode: Boolean,
|
||||
create: Boolean,
|
||||
where: String,
|
||||
refnode: Object
|
||||
|
@ -76,11 +79,27 @@ export default {
|
|||
}
|
||||
|
||||
this.editorShow = false;
|
||||
},
|
||||
deleteCast: function() {
|
||||
console.log("Deleting cast");
|
||||
axios.delete('/api/castnode/'+this.item.node.id+'/'
|
||||
).then( () => {
|
||||
this.loading = false;
|
||||
this.$root.$emit('updateData',"castNode delete update");
|
||||
}).catch(e => {
|
||||
this.errors.push(e);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
||||
<style scoped>
|
||||
.changed {
|
||||
background-color: yellow;
|
||||
}
|
||||
.delete {
|
||||
background-color: #ff6666;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -23,7 +23,8 @@
|
|||
|
||||
<template v-else v-bind:class="changedObject">
|
||||
<p v-html="currentText"></p>
|
||||
<button v-if="editorMode" v-on:click="editorShow=!editorShow">Upravit</button>
|
||||
<button v-if="editorMode" v-on:click="editorShow = !editorShow">Upravit</button>
|
||||
<button v-if="editorMode" v-on:click="deleteText" class="delete">Smazat</button>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
@ -162,6 +163,16 @@ export default {
|
|||
}
|
||||
this.editorShow = false;
|
||||
},
|
||||
deleteText: function() {
|
||||
console.log("Deleting text");
|
||||
axios.delete('/api/textnode/'+this.item.node.id+'/'
|
||||
).then( () => {
|
||||
this.loading = false;
|
||||
this.$root.$emit('updateData',"textNode delete update");
|
||||
}).catch(e => {
|
||||
this.errors.push(e);
|
||||
});
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
@ -169,6 +180,9 @@ export default {
|
|||
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
||||
<style scoped>
|
||||
.changed {
|
||||
background-color: 'yellow';
|
||||
background-color: yellow;
|
||||
}
|
||||
.delete {
|
||||
background-color: #ff6666;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
<div id="loading" v-if="loading">
|
||||
Loading...
|
||||
</div>
|
||||
<div v-else>
|
||||
<!--pre>
|
||||
{{item}}
|
||||
</pre-->
|
||||
|
@ -11,6 +12,7 @@
|
|||
<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>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ const pages = {
|
|||
module.exports = {
|
||||
pages: pages,
|
||||
filenameHashing: false,
|
||||
productionSourceMap: false,
|
||||
productionSourceMap: true,
|
||||
publicPath: process.env.NODE_ENV === 'production'
|
||||
? '/static/seminar/vue/'
|
||||
: 'http://localhost:8080/',
|
||||
|
@ -23,6 +23,7 @@ module.exports = {
|
|||
|
||||
chainWebpack: config => {
|
||||
|
||||
config.optimization.minimize(false)
|
||||
config.optimization
|
||||
.splitChunks({
|
||||
cacheGroups: {
|
||||
|
@ -33,7 +34,7 @@ module.exports = {
|
|||
priority: 1
|
||||
},
|
||||
},
|
||||
});
|
||||
}).minimize(false);
|
||||
|
||||
Object.keys(pages).forEach(page => {
|
||||
config.plugins.delete(`html-${page}`);
|
||||
|
|
Loading…
Reference in a new issue