Dateiverwaltung für die WebBox
ulrich
2017-02-20 c509a016b6156e34034500803f8e18a2a9529940
Neuer Ordner hergestellt
3 files modified
149 ■■■■ changed files
src/java/de/uhilger/filecms/api/FileMgr.java 99 ●●●● patch | view | raw | blame | history
web/ui/index.html 3 ●●●● patch | view | raw | blame | history
web/ui/ui.js 47 ●●●●● patch | view | raw | blame | history
src/java/de/uhilger/filecms/api/FileMgr.java
@@ -42,26 +42,13 @@
  public static final String PUB_DIR_NAME = "Oeffentlich";
  public static final String HOME_DIR_NAME = "Persoenlicher Ordner";
  
  //private FileRef homeFolder;
  //private FileRef publicFolder;
  //private FileRef namedHomeFolder;
  //private FileRef namedPublicFolder;
  public String hallo() {
    return "Hallo Welt!";
  }
  
  public List<FileRef> list(String relPath) {
    List<FileRef> files = new ArrayList();
    if(relPath.length() == 0) {
      /*
      publicFolder = new FileRef(getUserPubDir().getAbsolutePath(), true);
      logger.info(publicFolder.getAbsolutePath());
      homeFolder = new FileRef(getUserHomeDir().getAbsolutePath(), true);
      logger.info(homeFolder.getAbsolutePath());
      */
      FileRef namedPublicFolder = new FileRef(PUB_DIR_NAME, true);
      logger.finer(namedPublicFolder.getAbsolutePath());
      FileRef namedHomeFolder = new FileRef(HOME_DIR_NAME, true);
@@ -70,20 +57,6 @@
      files.add(namedHomeFolder);
      files.add(namedPublicFolder);
    } else {
      /*
      logger.finer(relPath);
      String targetPath = null;
      if(relPath.startsWith(PUB_DIR_NAME)) {
        targetPath = PUB_DIR_PATH + getUserName() + "/" + relPath.substring(PUB_DIR_NAME.length());
      } else if(relPath.startsWith(HOME_DIR_NAME)) {
        targetPath = HOME_DIR_PATH + getUserName() + "/" + relPath.substring(HOME_DIR_NAME.length());
      } else {
        // kann eigentlich nicht sein..
      }
      logger.finer(targetPath);
      File targetDir = new File(getBase().getAbsolutePath(), targetPath);
      */
      LocalFileSystem fs = new LocalFileSystem();
      String path = getTargetDir(relPath).getAbsolutePath();
      logger.fine(path);
@@ -92,25 +65,39 @@
        files.add(fileRefs[i]);
        logger.finer("added " + fileRefs[i].getAbsolutePath());
      }
      //files = Arrays.asList(fileRefs);
    }
    }
    return files;
  }
  
  public FileRef newFolder(String relPath, String folderName) {
    logger.finer(relPath);
    String targetPath = null;
    if(relPath.startsWith(PUB_DIR_NAME)) {
      targetPath = PUB_DIR_PATH + getUserName() + "/" + relPath.substring(PUB_DIR_NAME.length()) + "/" + folderName;
    } else if(relPath.startsWith(HOME_DIR_NAME)) {
      targetPath = HOME_DIR_PATH + getUserName() + "/" + relPath.substring(HOME_DIR_NAME.length()) + "/" + folderName;
    } else {
      // kann eigentlich nicht sein..
    }
    logger.finer(targetPath);
    File targetDir = new File(getBase().getAbsolutePath(), targetPath);
    targetDir.mkdirs();
    return new FileRef(targetDir.getAbsolutePath(), true);
  }
  private File getTargetDir(String relPath) {
      logger.finer(relPath);
      String targetPath = null;
      if(relPath.startsWith(PUB_DIR_NAME)) {
        targetPath = PUB_DIR_PATH + getUserName() + "/" + relPath.substring(PUB_DIR_NAME.length());
      } else if(relPath.startsWith(HOME_DIR_NAME)) {
        targetPath = HOME_DIR_PATH + getUserName() + "/" + relPath.substring(HOME_DIR_NAME.length());
      } else {
        // kann eigentlich nicht sein..
      }
      logger.finer(targetPath);
      File targetDir = new File(getBase().getAbsolutePath(), targetPath);
      return targetDir;
    logger.finer(relPath);
    String targetPath = null;
    if(relPath.startsWith(PUB_DIR_NAME)) {
      targetPath = PUB_DIR_PATH + getUserName() + "/" + relPath.substring(PUB_DIR_NAME.length());
    } else if(relPath.startsWith(HOME_DIR_NAME)) {
      targetPath = HOME_DIR_PATH + getUserName() + "/" + relPath.substring(HOME_DIR_NAME.length());
    } else {
      // kann eigentlich nicht sein..
    }
    logger.finer(targetPath);
    File targetDir = new File(getBase().getAbsolutePath(), targetPath);
    return targetDir;
  }
  
  private FileRef getBase() {
@@ -122,18 +109,6 @@
    return base;
  }
  
  /*
  private File getUserPubDir() {
    File userDir = null;
    File daten = new File(getBase().getAbsolutePath());
    Object p = getRequest().getUserPrincipal();
    if(p instanceof Principal) {
      userDir = new File(daten, PUB_DIR_PATH + ((Principal) p).getName());
    }
    return userDir;
  }
  */
  private String getUserName() {
    String userName = null;
    Object p = getRequest().getUserPrincipal();
@@ -143,18 +118,6 @@
    return userName;
  }
  
  /*
  private File getUserHomeDir() {
    File userDir = null;
    File daten = new File(getBase().getAbsolutePath());
    Object p = getRequest().getUserPrincipal();
    if(p instanceof Principal) {
      userDir = new File(daten, HOME_DIR_PATH + ((Principal) p).getName());
    }
    return userDir;
  }
  */
  public FileRef saveTextFile(String relPath, String fileName, String contents) {
    FileRef savedFile = null;
    try {
@@ -162,10 +125,6 @@
      File daten = new File(datenRef.getAbsolutePath());
      Object p = getRequest().getUserPrincipal();
      if(p instanceof Principal) {
        /*
        File userDir = new File(daten, "www/" + ((Principal) p).getName());
        File saveDir = new File(userDir, relPath);
        */
        File targetFile = new File(getTargetDir(relPath), fileName);
        if(targetFile.exists()) {
          /*
web/ui/index.html
@@ -43,6 +43,7 @@
            <div class="dropdown-menu">
              <a id="newTextFile" class="dropdown-item" href="#">Neue Text-Datei..</a>
              <a class="dropdown-item" href="#">Neues Dokument..</a>
              <a id="newFolder" class="dropdown-item" href="#">Neuer Ordner..</a>
              <div class="dropdown-divider"></div>
              <a class="dropdown-item" href="#">Ansehen als Code</a>
              <a class="dropdown-item" href="#">Ansehen als Dokument</a>
@@ -169,7 +170,7 @@
                </button>
              </div>
              <div class="modal-body">
                <p>Dateiname?</p>
                <p id="dialogfrage">Dateiname?</p>
                <input class="form-control eingabe" type="text" size="20" maxlength="250" placeholder="Dateiname" name="dateiname" id="dateiname">
              </div>
              <div class="modal-footer">
web/ui/ui.js
@@ -5,10 +5,11 @@
  $('.codeeditor-space').hide();
  $('.code-editor-container').hide();
  $('#newTextFile').on('click', fm_menu_neue_textdatei);
  $('#newFolder').on('click', fm_menu_neuer_ordner);
  $('#editTextFile').on('click', fm_menu_textdatei_bearbeiten);
  $('#saveFile').on('click', fm_menu_datei_speichern);
  $('#closeFile').on('click', fm_menu_datei_schliessen);
  $('#myModal').on('hidden.bs.modal', function (e) {
  $('#saveModal').on('hidden.bs.modal', function (e) {
    $('#modal_ok').attr('onclick','').unbind('click');
  });
  $('#logout').click(fm_logout);  
@@ -59,11 +60,16 @@
  }
}
function fm_menu_neuer_ordner() {
  fm_get_new_folder();
}
function fm_bc_click() {
  var elem = this;
  var bcPfad = $(elem).attr('rpath');
  //console.log(relPath);
  if(bcPfad !== undefined) {
    pfad = bcPfad;
    fm_get_list(bcPfad);
  } else {
    pfad = '';
@@ -82,6 +88,33 @@
  fm_get(u, "json", function(resp) {
    $('#userMenu').text(resp.UserData.firstName);
  });  
}
function fm_get_new_folder() {
  $('#modal_ok').click(function() {
    // hier speichern
    var m = '?c=de.uhilger.filecms.api.FileMgr&m=newFolder&p=' + pfad + '&p=' + $('#dateiname').val();
    var u = '../svc' + m;
    fm_get(u, "json", function(resp) {
    });
    /*
    var m = '?c=de.uhilger.filecms.api.FileMgr&m=saveTextFile';
    var u = '../svc' + m;
    fm_post(u, {p1: pfad, p2: $('#dateiname').val(), p3: cm.getValue()}, function(resp) {
    });
    */
  });
  $('.modal-title').text('Neuer Ordner');
  $('#dialogfrage').text("Name?");
  $('#dateiname').val('');
  $('#dateiname').attr('placeholder', 'Ordnername');
  $('#saveModal').modal({
    keyboard: false,
    show: true
  });
}
function fm_get_file_content() {
@@ -107,8 +140,12 @@
  fm_get(u, "json", function(resp) {
    if(resp.List[0].FileRef !== undefined) {
      var files = new Array();
      for(var i = 0; i < resp.List[0].FileRef.length; i++) {
        files.push(new FileRef(resp.List[0].FileRef[i]));
      if(resp.List[0].FileRef instanceof Array) {
        for(var i = 0; i < resp.List[0].FileRef.length; i++) {
          files.push(new FileRef(resp.List[0].FileRef[i]));
        }
      } else {
        files.push(new FileRef(resp.List[0].FileRef));
      }
      var fl = new FileList(files);
      var template = $('#tpl-kacheln').html();
@@ -181,6 +218,10 @@
    });
  });
  $('.modal-title').text('Datei speichern');
  $('#dialogfrage').text("Dateiname?");
  $('#dateiname').val('');
  $('#dateiname').attr('placeholder', 'Dateiname');
  $('#saveModal').modal({
    keyboard: false,
    show: true