src/de/uhilger/mediaz/api/ListFileHandler.java | ●●●●● patch | view | raw | blame | history | |
src/de/uhilger/mediaz/api/StorageHandler.java | ●●●●● patch | view | raw | blame | history | |
src/de/uhilger/mediaz/entity/Einstellung.java | ●●●●● patch | view | raw | blame | history | |
src/de/uhilger/mediaz/store/FileStorage.java | ●●●●● patch | view | raw | blame | history | |
www/ui/data/tpl/einstellung_liste.tpl | ●●●●● patch | view | raw | blame | history | |
www/ui/data/tpl/form_einstellung.tpl | ●●●●● patch | view | raw | blame | history | |
www/ui/index.html | ●●●●● patch | view | raw | blame | history | |
www/ui/js/app.js | ●●●●● patch | view | raw | blame | history |
src/de/uhilger/mediaz/api/ListFileHandler.java
@@ -1,7 +1,19 @@ /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. Mediazentrale - Personal Media Center Copyright (C) 2021 Ulrich Hilger This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. */ package de.uhilger.mediaz.api; @@ -58,8 +70,6 @@ list.add(sf); } } //Gson gson = new Gson(); //String json = gson.toJson(fileNames); String json = jsonWithCustomType(list, "Medialiste"); logger.fine(json); e.sendResponseHeaders(200, json.length()); src/de/uhilger/mediaz/api/StorageHandler.java
@@ -143,7 +143,7 @@ String filename = ""; FileStorage fs = new FileStorage(App.getInitParameter(App.getRs(App.RB_AP_CONF))); Gson gson = new Gson(); logger.log(Level.FINE, "type: {0}", type); logger.log(Level.FINE, "type: {0}, token: {1}", new Object[]{type, fs.typeFromName(type).getType().getTypeName()}); Object o = gson.fromJson(body, fs.typeFromName(type).getType()); if(o instanceof Entity) { Object antwortObjekt = fs.write((Entity) o, overwrite); src/de/uhilger/mediaz/entity/Einstellung.java
@@ -1,7 +1,19 @@ /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. Mediazentrale - Personal Media Center Copyright (C) 2021 Ulrich Hilger This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. */ package de.uhilger.mediaz.entity; @@ -9,7 +21,7 @@ * * @author ulrich */ public class Einstellung { public class Einstellung implements Entity { private String key; private String value; @@ -29,5 +41,10 @@ this.value = value; } @Override public String getName() { return key; } } src/de/uhilger/mediaz/store/FileStorage.java
@@ -22,6 +22,7 @@ import de.uhilger.mediaz.App; import de.uhilger.mediaz.Server; import de.uhilger.mediaz.entity.Ablageort; import de.uhilger.mediaz.entity.Einstellung; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; @@ -54,17 +55,19 @@ /** StorageType Ablageort */ public static final String ST_ABLAGEORT = "Ablageort"; private String fileBase; private final String fileBase; private Map<String, TypeToken> types; private final Map<String, TypeToken> types; public FileStorage(String base) { this.fileBase = base; // Beispiel: TypeToken<List<String>> list = new TypeToken<List<String>>() {}; TypeToken<Ablageort> ttAblageort = new TypeToken<Ablageort>() {}; TypeToken<Einstellung> ttEinstellung = new TypeToken<Einstellung>() {}; types = new HashMap(); types.put(Ablageort.class.getSimpleName(), ttAblageort); types.put(Einstellung.class.getSimpleName(), ttEinstellung); } /** @@ -73,12 +76,16 @@ * Es wird in den Ordner geschrieben, der von conf angegeben ist * * Wenn es z.B. ein Ablage-Objekt ist, wird das Objekt in die Datei * [conf]/Ablage/[name der Ablage].json geschrieben * * Der Name der Ablage muss eindeutig sein [conf]/Ablage/[name der Ablage].json geschrieben Der Name der Ablage muss eindeutig sein * * * @param entity * @param entity das Objekt, das geschrieben werden soll * @param overwrite true, wenn Aenderung, false fuer neue Elemente * @return die Datei oder null, wenn die Datei existiert und ein * neues Element (overwrite=false) uebergeben wurde * @throws java.io.IOException */ public File writeToFile(Entity entity, boolean overwrite) throws IOException { String className = entity.getClass().getSimpleName(); @@ -86,9 +93,6 @@ File dir = new File(fileBase, className); dir.mkdirs(); File file = new File(dir, entity.getName()); //if(file.exists()) { // file.delete(); //} if(file.exists() && !overwrite) { return null; } else { www/ui/data/tpl/einstellung_liste.tpl
New file @@ -0,0 +1,11 @@ <div class='entity-formular'> <div class='entity-liste-kopf'> Einstellungen <button class='ctrl-btn' id='neu-btn' title='Neu'><i class='icon-doc'></i></button> </div> <ul class='entity-liste'> {{#ArrayList}} <li class='entity-eintrag'>{{.}}</li> {{/ArrayList}} </ul> </div> www/ui/data/tpl/form_einstellung.tpl
New file @@ -0,0 +1,14 @@ <div class="entity-formular"> Einstellung <input class="entity-element" type="text" id="einstellung-key" placeholder="Key" value="{{key}}" /> <input class="entity-element" type="text" id="einstellung-value" placeholder="Pfad" value="{{value}}" /> <div class="entity-buttons"> <button class="button-primary" id="ok-btn">Speichern</button> <button class="button" id="cancel-btn">Abbrechen</button> <button class="button" id="loeschen-btn">Löschen</button> </div> </div> www/ui/index.html
@@ -49,6 +49,7 @@ <a id="mi-orte"><i class="icon-database"></i> Kataloge</a> <a id="mi-player"><i class="icon-play"></i> Abspieler</a> <a id="mi-radio"><i class="icon-ellipsis-vert"></i> Radio</a> <a id="mi-prefs"><i class="icon-sliders"></i> Einstellungen</a> </div> </div> </div> www/ui/js/app.js
@@ -4,6 +4,10 @@ this.url = u; } function Einstellung(k, v) { this.key = k; this.value = v; } function Mediazentrale() { @@ -65,6 +69,8 @@ } }; /* Die folgenden '_liste' Funktionen koennen noch vereinheitlicht werden */ this.ablageort_liste = function() { self.http_get('../api/store/Ablageort/', function (responseText) { self.vorlage_laden_und_fuellen("data/tpl/ablageort_liste.tpl", JSON.parse(responseText), function (html) { @@ -78,6 +84,73 @@ }); self.addEvtListener('#neu-btn', 'click', function (event) { eval("self.ablageort_form" + "(this)"); }); }); }); }; this.prefs_liste = function() { self.http_get('../api/store/Einstellung/', function (responseText) { self.vorlage_laden_und_fuellen("data/tpl/einstellung_liste.tpl", JSON.parse(responseText), function (html) { document.querySelector(".zentraler-inhalt").innerHTML = html; self.addEvtListener('.entity-eintrag', 'click', function (event) { var t = event.target; self.http_get('../api/store/Einstellung/' + t.textContent, function(responseText){ var einstellung = JSON.parse(responseText); self.prefs_form(einstellung); }); }); self.addEvtListener('#neu-btn', 'click', function (event) { eval("self.prefs_form" + "(this)"); }); }); }); }; /* Die folgenden '_form' Funktionen koennen noch vereinheitlicht werden */ this.prefs_form = function(k) { self.vorlage_laden_und_fuellen("data/tpl/form_einstellung.tpl", k, function (html) { document.querySelector(".zentraler-inhalt").innerHTML = html; self.addEvtListener('#ok-btn', 'click', function () { var pkey = document.querySelector('#einstellung-key').value; pkey = pkey.replace(' ', '').replace(/[\W]+/g, ''); var pref = new Einstellung( pkey, document.querySelector('#einstellung-value').value ); var daten = JSON.stringify(pref); if(typeof k === "undefined" || k.key !== pkey) { // neu self.http_post('../api/store/Einstellung', daten, function (responseText) { // hier die Antwort verarbeiten }); } else { // aendern self.http_put('../api/store/Einstellung', daten, function (responseText) { // hier die Antwort verarbeiten }); } //document.querySelector(".zentraler-inhalt").innerHTML = ''; self.prefs_liste(); }); self.addEvtListener('#cancel-btn', 'click', function () { //document.querySelector(".zentraler-inhalt").innerHTML = ''; self.prefs_liste(); }); self.addEvtListener('#loeschen-btn', 'click', function() { var pkey = document.querySelector('#einstellung-key').value; var dlgdata = {"del-elem": pkey}; self.dialog_laden_und_zeigen('data/tpl/dlg-loeschen.tpl', dlgdata, function() { self.addEvtListener('#nein-btn', 'click', self.dialog_schliessen); self.addEvtListener('#ja-btn', 'click', function() { self.http_delete('../api/store/Einstellung/' + pkey, '', function (responseText) { // hier die Antwort verarbeiten self.dialog_schliessen(); //document.querySelector(".zentraler-inhalt").innerHTML = ''; self.prefs_liste(); }); }); }); }); }); @@ -226,6 +299,7 @@ self.addEvtListener('#mi-katalog', 'click', self.media_liste); self.addEvtListener('#mi-orte', 'click', self.ablageort_liste); self.addEvtListener('#mi-prefs', 'click', self.prefs_liste); //self.addEvtListener('#mi-list', 'click', self.media_liste); self.fusszeile_umschalten();