From 08eb4edae5280829fb9bef1ac962c2f9053c399c Mon Sep 17 00:00:00 2001 From: darthsandmann Date: Wed, 14 Dec 2016 12:45:42 +0100 Subject: [PATCH] Edit, Delete --- .../app/__pycache__/category.cpython-35.pyc | Bin 1010 -> 1643 bytes .../app/__pycache__/database.cpython-35.pyc | Bin 5136 -> 5125 bytes .../ppm2/app/__pycache__/eval.cpython-35.pyc | Bin 2793 -> 2783 bytes Praktikum2/ppm2/app/category.py | 46 +++++++-- Praktikum2/ppm2/app/database.py | 2 +- Praktikum2/ppm2/data/Angebote/23.json | 13 --- Praktikum2/ppm2/data/Angebote/26.json | 13 --- Praktikum2/ppm2/data/Firmen/last.json | 2 +- Praktikum2/ppm2/data/Lehrender/7.json | 7 -- Praktikum2/ppm2/data/Studenten/10.json | 6 -- Praktikum2/ppm2/data/Studenten/13.json | 4 +- Praktikum2/ppm2/data/Studenten/9.json | 6 -- Praktikum2/ppm2/data/Studenten/last.json | 2 +- Praktikum2/ppm2/static/js/ppm.js | 94 +++++++++++++++--- Praktikum2/ppm2/templates/detail.tpl | 58 +++++++++++ 15 files changed, 180 insertions(+), 73 deletions(-) delete mode 100644 Praktikum2/ppm2/data/Angebote/23.json delete mode 100644 Praktikum2/ppm2/data/Angebote/26.json delete mode 100644 Praktikum2/ppm2/data/Lehrender/7.json delete mode 100644 Praktikum2/ppm2/data/Studenten/10.json delete mode 100644 Praktikum2/ppm2/data/Studenten/9.json create mode 100644 Praktikum2/ppm2/templates/detail.tpl diff --git a/Praktikum2/ppm2/app/__pycache__/category.cpython-35.pyc b/Praktikum2/ppm2/app/__pycache__/category.cpython-35.pyc index 478bda033196aa8ae3c8c379dfa55b5c088c2373..adc49b3b3753af4d808be34241c9e30d30488d25 100644 GIT binary patch literal 1643 zcmZWp&2HO95S}HM6wOGD3nyt6eKw9~G%%h{RPnQwk}@AP`%AH(l|ei#t_Mc0M|{TQ=+ ziY3KgP)-!Jw4g{>zC*b~3zs67#7XK>D(M5XBq>RkV0(OYGV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CAz~ VNs;5`djd5~Y%U-f*U1UOO99P+BNqSw diff --git a/Praktikum2/ppm2/app/__pycache__/eval.cpython-35.pyc b/Praktikum2/ppm2/app/__pycache__/eval.cpython-35.pyc index 04930eecb080f8b35372999179df61850a3da907..5cc8dc9748ef81b85582c6c015606b24d82ea487 100644 GIT binary patch delta 37 scmaDUdS8@XjF*>7THb#nyBs6Go_=U?YEiL%c4DT!duGXIJI2+V0J#?mZvX%Q delta 47 zcmcaF`cjl#jF*>d+IPQ=>~f5f7W$#ZsYS*5*@>C@#mSkeN%{KjnI%4nNt;a=S91aY DY$^|a diff --git a/Praktikum2/ppm2/app/category.py b/Praktikum2/ppm2/app/category.py index 649364c..5987861 100644 --- a/Praktikum2/ppm2/app/category.py +++ b/Praktikum2/ppm2/app/category.py @@ -16,18 +16,44 @@ class Category(object): self.db = database.Database() #------------------------------------------------------- - def GET(self, cat=None): + def GET(self, cat, view, id=None): #------------------------------------------------------- data = {} - if(cat != None): + if(cat != "Index"): self.db.ReadAll() - data['content'] = {} - data['headings'] = {} - data['category'] = cat - data['content'] = self.db.data[cat] - if(len(data['content']) != 0): - print(len(data['content'])) - contentFirst = list(data['content'].keys())[0] - data['headings'] = list(data['content'][contentFirst].keys()) + if(view == "List"): + data['content'] = {} + data['headings'] = {} + data['category'] = cat + data['content'] = self.db.data[cat] + if(len(data['content']) != 0): + print(len(data['content'])) + contentFirst = list(data['content'].keys())[0] + data['headings'] = list(data['content'][contentFirst].keys()) + elif(view == "Detail"): + data['category'] = cat + if(id != None): + data['id'] = id + data['content'] = self.db.ReadEntry(cat, id) + else: + data['id'] = None + data['content'] = self.db.GetDefault(cat) + if(cat == 'Angebote'): + data['Firmen'] = self.db.data['Firmen'] print(data) return json.dumps(data) + + #------------------------------------------------------- + def POST(self, cat, **data): + #------------------------------------------------------- + self.db.Save(data, cat) + print(data) + return self.GET(cat, "List") + + + #------------------------------------------------------- + def DELETE(self, cat, id): + #------------------------------------------------------- + print("Delete",cat,id) + self.db.Delete(cat, id) + return self.GET(cat, "List") diff --git a/Praktikum2/ppm2/app/database.py b/Praktikum2/ppm2/app/database.py index 36c072a..14d2465 100644 --- a/Praktikum2/ppm2/app/database.py +++ b/Praktikum2/ppm2/app/database.py @@ -71,7 +71,7 @@ class Database(object): status_b = False id = data['id'] print("ID: ", id, "\n") - if(id != "None"): + if(id != ""): if id in self.data[category]: file = codecs.open(os.path.join('data', category, id+'.json'), 'w', 'utf-8') file.write(json.dumps(data, indent=3, ensure_ascii=True)) diff --git a/Praktikum2/ppm2/data/Angebote/23.json b/Praktikum2/ppm2/data/Angebote/23.json deleted file mode 100644 index b28de59..0000000 --- a/Praktikum2/ppm2/data/Angebote/23.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "Name": "Angebot IBM 1", - "ZeitraumBis": "01.01.2018", - "id": "23", - "Firmenbetreuer": "Sepp Meine", - "Firma": "IBM", - "Voraussetzungen": "Keine", - "Lehrender": "7", - "Status": "aktuell", - "Beschreibung": "Praxisphasenplatz bei IBM", - "ZeitraumVon": "01.01.2017", - "Student": "9" -} \ No newline at end of file diff --git a/Praktikum2/ppm2/data/Angebote/26.json b/Praktikum2/ppm2/data/Angebote/26.json deleted file mode 100644 index f2fd625..0000000 --- a/Praktikum2/ppm2/data/Angebote/26.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "id": "26", - "ZeitraumVon": "02.02.2019", - "Firma": "Apple", - "Student": "10", - "Beschreibung": "Beschreibung", - "Name": "Name", - "Lehrender": "5", - "Firmenbetreuer": "Firmenbetreuer3", - "Voraussetzungen": "Kein", - "Status": "aktuell", - "ZeitraumBis": "02.02.2020" -} \ No newline at end of file diff --git a/Praktikum2/ppm2/data/Firmen/last.json b/Praktikum2/ppm2/data/Firmen/last.json index 62f9457..c793025 100644 --- a/Praktikum2/ppm2/data/Firmen/last.json +++ b/Praktikum2/ppm2/data/Firmen/last.json @@ -1 +1 @@ -6 \ No newline at end of file +7 \ No newline at end of file diff --git a/Praktikum2/ppm2/data/Lehrender/7.json b/Praktikum2/ppm2/data/Lehrender/7.json deleted file mode 100644 index 2f4b91f..0000000 --- a/Praktikum2/ppm2/data/Lehrender/7.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "Titel": "Prof", - "id": "7", - "Lehrgebiet": "Informatik", - "Name": "Adalbert", - "Vorname": "Bastian" -} \ No newline at end of file diff --git a/Praktikum2/ppm2/data/Studenten/10.json b/Praktikum2/ppm2/data/Studenten/10.json deleted file mode 100644 index 31ac8db..0000000 --- a/Praktikum2/ppm2/data/Studenten/10.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "Vorname": "Timo", - "Name": "Ben", - "Matrikelnummer": "3", - "id": "10" -} \ No newline at end of file diff --git a/Praktikum2/ppm2/data/Studenten/13.json b/Praktikum2/ppm2/data/Studenten/13.json index e463503..9355135 100644 --- a/Praktikum2/ppm2/data/Studenten/13.json +++ b/Praktikum2/ppm2/data/Studenten/13.json @@ -1,6 +1,6 @@ { "id": "13", - "Name": "Edmund", "Vorname": "Adalbert", - "Matrikelnummer": "1" + "Matrikelnummer": "1", + "Name": "Edmund" } \ No newline at end of file diff --git a/Praktikum2/ppm2/data/Studenten/9.json b/Praktikum2/ppm2/data/Studenten/9.json deleted file mode 100644 index a4bd70d..0000000 --- a/Praktikum2/ppm2/data/Studenten/9.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "Vorname": "Gregor", - "Name": "Klemens", - "Matrikelnummer": "2", - "id": "9" -} \ No newline at end of file diff --git a/Praktikum2/ppm2/data/Studenten/last.json b/Praktikum2/ppm2/data/Studenten/last.json index da2d398..3f10ffe 100644 --- a/Praktikum2/ppm2/data/Studenten/last.json +++ b/Praktikum2/ppm2/data/Studenten/last.json @@ -1 +1 @@ -14 \ No newline at end of file +15 \ No newline at end of file diff --git a/Praktikum2/ppm2/static/js/ppm.js b/Praktikum2/ppm2/static/js/ppm.js index 4761938..0049a30 100644 --- a/Praktikum2/ppm2/static/js/ppm.js +++ b/Praktikum2/ppm2/static/js/ppm.js @@ -42,27 +42,27 @@ class PPM { case 'index': - this.LoadContent('/category/', 'index.tpl'); + this.LoadContent('/category/?cat=Index&view=List', 'index.tpl'); break; case 'categoryStudenten': - this.LoadContent('/category/?cat=Studenten', 'list.tpl'); + this.LoadContent('/category/?cat=Studenten&view=List', 'list.tpl'); break case 'categoryLehrender': - this.LoadContent('/category/?cat=Lehrender', 'list.tpl'); + this.LoadContent('/category/?cat=Lehrender&view=List', 'list.tpl'); break case 'categoryFirmen': - this.LoadContent('/category/?cat=Firmen', 'list.tpl'); + this.LoadContent('/category/?cat=Firmen&view=List', 'list.tpl'); break case 'choice': - this.LoadContent('/choice', 'listChoice.tpl'); + this.LoadContent('/choice/?view=List', 'listChoice.tpl'); break case 'evalStudenten': @@ -83,45 +83,81 @@ class PPM case 'NewStudenten': console.log("NewStudenten"); + this.LoadContent('/category/?cat=Studenten&view=Detail', 'detail.tpl'); break case 'NewLehrender': console.log("NewLehrender"); + this.LoadContent('/category/?cat=Lehrenden&view=Detail', 'detail.tpl'); break case 'NewFirmen': console.log("NewFirmen"); + this.LoadContent('/category/?cat=Firmen&view=Detail', 'detail.tpl'); break case 'ModifyStudenten': console.log("ModifyStudenten: ", selectedId); + this.LoadContent('/category/?cat=Studenten&view=Detail&id='+ selectedId, 'detail.tpl'); break - case 'ModifyLehrenden': + case 'ModifyLehrender': - console.log("ModifyLehrenden", selectedId); + console.log("ModifyLehrender", selectedId); + this.LoadContent('/category/?cat=Lehrender&view=Detail&id='+ selectedId, 'detail.tpl'); break case 'ModifyFirmen': console.log("ModifyFirmen", selectedId); + this.LoadContent('/category/?cat=Firmen&view=Detail&id='+ selectedId, 'detail.tpl'); break case 'DeleteStudenten': console.log("DeleteStudenten", selectedId); + if (confirm("Soll der Eintrag wirklich geloescht werden?")) { + console.log("DELETE"); + this.DeleteContent('/category/?cat=Studenten&id='+selectedId, 'categoryStudenten'); + } break - case 'DeleteLehrenden': + case 'DeleteLehrender': - console.log("DeleteLehrenden", selectedId); + console.log("DeleteLehrender", selectedId); + if (confirm("Soll der Eintrag wirklich geloescht werden?")) { + console.log("DELETE"); + this.DeleteContent('/category/?cat=Lehrender&id='+selectedId, 'categoryLehrender'); + } break case 'DeleteFirmen': console.log("DeleteFirmen", selectedId); + if (confirm("Soll der Eintrag wirklich geloescht werden?")) { + console.log("DELETE"); + this.DeleteContent('/category/?cat=Firmen&id='+selectedId, 'categoryFirmen'); + } + break + + case 'SaveCategoryStudenten': + + var data = $("#idForm").serialize(); + this.SaveContent('/category/?cat=Studenten&'+data, 'categoryStudenten'); + break + + case 'SaveCategoryLehrende': + + var data = $("#idForm").serialize(); + this.SaveContent('/category/?cat=Lehrender&'+data, 'categoryLehrender'); + break + + case 'SaveCategoryFirmen': + + var data = $("#idForm").serialize(); + this.SaveContent('/category/?cat=Firmen&'+data, 'categoryFirmen'); break default: @@ -139,10 +175,10 @@ class PPM context: this }) .done(function (json) { - //console.log("JSON: ", json); + console.log("JSON: ", json); var result = this.TemplateManager_o.execute_px( template, json ); - //console.log("RESULT: ", result); + console.log("RESULT: ", result); //$( ".clContent" ).replaceWith(result); $( ".clContent" ).empty(); @@ -150,10 +186,42 @@ class PPM this.BodyTableSelect(); console.log("TM DONE"); }) - .fail(function(jqXHR_opl, textStatus_spl) { - alert( "[PPM] Fehler bei Anforderung: " + textStatus_spl ); + .fail(function(jqXHR_opl, textStatus) { + alert( "[PPM] Fehler bei Anforderung: " + textStatus ); }); } + + SaveContent( path, menu ) + { + $.ajax({ + dataType: "json", + url: path, + type: 'POST', + context: this + }) + .done(function (json) { + this.Menu(menu); + }) + .fail(function(jqXHR_opl, textStatus) { + alert( "[PPM] Fehler bei Anforderung: " + textStatus ); + }); + } + + DeleteContent( path, menu ) + { + $.ajax({ + dataType: "json", + url: path, + type: 'DELETE', + context: this + }) + .done(function (json) { + this.Menu(menu); + }) + .fail(function(jqXHR_opl, textStatus) { + alert( "[PPM] Fehler bei Anforderung: " + textStatus ); + }); + } } diff --git a/Praktikum2/ppm2/templates/detail.tpl b/Praktikum2/ppm2/templates/detail.tpl new file mode 100644 index 0000000..e1cc601 --- /dev/null +++ b/Praktikum2/ppm2/templates/detail.tpl @@ -0,0 +1,58 @@ +

+ #context['category']#: Ihre Daten +

+
+
+ + + @if context['category'] != 'Angebote'@ + @for field in context['content']@ + @if field!='id' && field!='Status'@ +
+ + + @else@ + "" id="#field#" name="#field#" /> + @endif@ +
+ @endif@ + @endfor@ + @else@ + + + + + + @for field in context['content']@ + @if field!='id' && field!='Status' && field!='ZeitraumVon' && field!='ZeitraumBis' && field!='Lehrender' && field!='Student'@ +
+ + @if field!='Firma'@ + + @else@ + "" id="#field#" name="#field#" /> + @endif@ + @else@ + + @endif@ +
+ @endif@ + @endfor@ + @endif@ +
+ + + +
\ No newline at end of file