Search in sources :

Example 76 with HTMLWriter

use of web.HTMLWriter in project common by zenlunatics.

the class Admin method writeColumns.

// --------------------------------------------------------------------------
private void writeColumns(String table, Request request) throws IOException {
    JDBCTable jdbc_table = request.db.getTable(table);
    String[] column_names = jdbc_table.getColumnNamesAll();
    HTMLWriter writer = request.writer;
    writer.write("<table class=\"table table-condensed table-bordered\" style=\"width:auto;\"><tr><th>name</th><th>type</th><th>default</th><th>nullable</th><th>references</th><th>actions</th></tr>");
    for (String column : column_names) {
        writer.write("<tr><td onclick=\"column_rename('").write(table).write("','").write(column).write("',function(){this.ancestorWithClass('tab-pane').replace()}.bind(this))\" style=\"cursor:pointer;\">");
        writer.write(column);
        writer.write("</td><td onclick=\"new Dialog({url:'admin?action=get_column_form&table=").write(table).write("&column=").write(column).write("',title:'Edit Column',owner:this.ancestorWithClass('tab-pane'),ok:true,cancel:true})\" style=\"cursor:pointer;\">");
        JDBCColumn jdbc_column = jdbc_table.getColumn(column);
        int size = jdbc_column.size;
        String type_name = jdbc_column.type_name;
        writer.write(type_name);
        if (type_name.endsWith("CHAR") && size > 0) {
            writer.write('(');
            writer.write(Integer.toString(size));
            writer.write(')');
        }
        if (column.equals("id"))
            writer.write("</td><td>");
        else {
            writer.write("</td><td onclick=\"new Dialog({url:'admin?action=get default form&table=").write(table).write("&column=").write(column).write("',title:'Set Default',owner:this.ancestorWithClass('tab-pane'),ok:true,cancel:true})\" style=\"cursor:pointer;\">");
            writer.write(jdbc_column.getDefaultValue());
        }
        writer.write("</td><td>");
        writer.setAttribute("onchange", "XHR_post('admin','action='+(this.checked?'drop':'set')+'_not_null&table=" + table + "&column=" + column + "',function(){this.ancestorWithClass('tab-pane').replace()}.bind(this))");
        writer.checkbox(null, null, null, jdbc_column.isNullable(), true);
        writer.write("</td><td>");
        if (jdbc_column.getPrimaryTable() != null)
            writer.write(jdbc_column.getPrimaryTable());
        else
            writer.nbsp();
        writer.write("</td><td>");
        writer.aOnClick("drop", "column_drop('" + table + "','" + column + "',function(){this.ancestorWithClass('tab-pane').replace()}.bind(this))");
        writer.write(",&nbsp;");
        writer.aOnClick("index", "XHR_post('admin','action=column_index&table=" + table + "&column=" + column + "',function(){this.ancestorWithClass('tab-pane').replace()}.bind(this))");
        writer.write("</td></tr>");
    }
    writer.write("</table>");
}
Also used : HTMLWriter(web.HTMLWriter) JDBCTable(db.JDBCTable) JDBCColumn(db.JDBCColumn)

Example 77 with HTMLWriter

use of web.HTMLWriter in project common by zenlunatics.

the class Admin method writeTablePane.

// --------------------------------------------------------------------------
private void writeTablePane(String table, Request request) throws IOException, SQLException {
    HTMLWriter writer = request.writer;
    writer.h3(table);
    NavBar nav_bar = new NavBar(writer).setInverse(true).open();
    nav_bar.aOnClick("add column", "new Dialog({url:context+'/admin?action=get_column_form&table=" + table + "',title:'Add Column',owner:this.ancestorWithClass('tab-pane'),ok:true,cancel:true})");
    nav_bar.aOnClick("delete where...", "table_delete('" + table + "')");
    nav_bar.aOnClick("delete all rows", "truncate_table('" + table + "')");
    nav_bar.aOnClick("drop", "table_drop('" + table + "')");
    int num_rows = request.db.countRows(table, null);
    nav_bar.aOnClick("edit " + num_rows + (num_rows == 1 ? " row" : " rows"), "$(this).ancestorWithClass('tab-pane').getLast().replace('admin?action=edit_table&table=" + table + "')");
    nav_bar.aOnClick("export", "$(this).ancestorWithClass('tab-pane').getLast().replace('admin?action=get_method_form&class=Admin&method=exportCSV&table=" + table + "')");
    nav_bar.aOnClick("import", "$(this).ancestorWithClass('tab-pane').getLast().replace('admin?action=get_method_form&class=Admin&method=importCSV&table=" + table + "')");
    nav_bar.aOnClick("rename", "table_rename('" + table + "')");
    nav_bar.dropdownOpen("generate");
    nav_bar.aOnClick("JDBCTable", "$(this).ancestorWithClass('tab-pane').getLast().replace('admin?action=generate jdbctable&table=" + table + "')");
    nav_bar.aOnClick("SQL", "$(this).ancestorWithClass('tab-pane').getLast().replace('admin?action=generate sql&table=" + table + "')");
    nav_bar.dropdownClose();
    nav_bar.close();
    writer.h4("columns");
    writeColumns(table, request);
    writer.h4("indexes");
    writeIndexes(request.db, table, writer);
    List<String[]> referencing_tables = request.db.getForeignKeys(table);
    if (referencing_tables.size() > 0) {
        writer.write("<p><b>referenced by: </b>");
        for (int i = 0; i < referencing_tables.size(); i++) {
            if (i > 0)
                writer.write(", ");
            writer.write(referencing_tables.get(i)[0] + '(' + referencing_tables.get(i)[1] + ')');
        }
        writer.write("</p>");
    }
    request.writer.write("<div></div>");
}
Also used : HTMLWriter(web.HTMLWriter) NavBar(web.NavBar)

Example 78 with HTMLWriter

use of web.HTMLWriter in project common by zenlunatics.

the class Admin method writeSchemaDiffForm.

// --------------------------------------------------------------------------
private void writeSchemaDiffForm(Request request) throws IOException {
    HTMLWriter writer = request.writer;
    Table table = new Table(request.writer);
    table.tr().td("url").td();
    writer.setAttribute("id", "url");
    writer.textInput("url", "60", null);
    table.close();
    writer.aButtonOnClick("diff", "XHR_get('admin?action=schema_diff&url='+$('url').value,function(t){$(this).getParent().getNext().set('html',t)}.bind(this))");
    writer.write("<div></div>");
}
Also used : HTMLWriter(web.HTMLWriter) Table(web.Table) JDBCTable(db.JDBCTable)

Example 79 with HTMLWriter

use of web.HTMLWriter in project common by zenlunatics.

the class Admin method writeViewDefCache.

// --------------------------------------------------------------------------
private void writeViewDefCache(Request request) throws IOException {
    String remove = request.getParameter("remove");
    if (remove != null)
        request.releaseViewDef(remove);
    HTMLWriter writer = request.writer;
    Table table = new Table(writer).addClass("table table-condensed table-striped").addStyle("width", "auto");
    Map<String, ViewDef> view_defs = request.site.getViewDefs();
    for (String name : view_defs.keySet()) {
        table.tr().td(name).td();
        DBObject.write(view_defs.get(name), writer);
        table.td();
        writer.aOnClick("remove", componentReplaceJS("action=get_view_def_cache&remove=" + name, request));
    }
    table.close();
}
Also used : HTMLWriter(web.HTMLWriter) Table(web.Table) JDBCTable(db.JDBCTable) ViewDef(db.ViewDef)

Example 80 with HTMLWriter

use of web.HTMLWriter in project common by zenlunatics.

the class Admin method importFile.

// --------------------------------------------------------------------------
private void importFile(Request request) throws IOException {
    String step = request.getParameter("step");
    HTMLWriter writer = request.writer;
    if (step == null) {
        String id = writer.componentOpen(null, null);
        web.Form form = componentFormOpen(id, request).setSubmitText("Start");
        writer.hiddenInput("action", "import file");
        writer.hiddenInput("step", "2");
        form.rowOpen("filename");
        writer.textInput("filename", null, null);
        form.close();
        writer.tagClose();
    } else if ("2".equals(step)) {
        String filename = request.getParameter("filename");
        BufferedReader br = new BufferedReader(new FileReader(request.site.getBaseFilePath().append(filename).toString()));
        String l = br.readLine();
        br.close();
        writer.write("$('").write(request.getParameter("id")).write("').innerHTML='");
        web.Form form = componentFormOpen(null, request).setSubmitText("Import");
        writer.hiddenInput("action", "import file");
        writer.hiddenInput("filename", filename);
        writer.hiddenInput("step", "3");
        form.rowOpen("table");
        writer.textInput("table", null, null);
        form.rowOpen("columns");
        Table table = new Table(writer);
        String[] types = new String[] { "INT", "VARCHAR" };
        String[] columns = l.split("\t");
        for (String column : columns) {
            table.tr().td();
            writer.checkbox("col" + column, column, null, true, false);
            table.td();
            writer.radioButtons(column, types, null, null);
        }
        table.close();
        form.close();
        writer.write('\'');
    } else if ("3".equals(step)) {
        StringBuilder sb = new StringBuilder();
        Enumeration<String> parameter_names = request.getParameterNames();
        while (parameter_names.hasMoreElements()) {
            String parameter_name = parameter_names.nextElement();
            if (parameter_name.startsWith("col")) {
                if (sb.length() > 0)
                    sb.append(',');
                String column = parameter_name.substring(3);
                sb.append(column);
                sb.append(' ');
                sb.append(request.getParameter(column));
            }
        }
        String table = request.getParameter("table");
        request.db.createTable(table, sb.toString());
        String filename = request.getParameter("filename");
        BufferedReader br = new BufferedReader(new FileReader(request.site.getBaseFilePath().append(filename).toString()));
        String l = br.readLine();
        String[] columns = l.split("\t");
        l = br.readLine();
        NameValuePairs name_value_pairs = new NameValuePairs();
        while (l != null) {
            String[] values = l.split("\t");
            for (String column : columns) if (request.getParameter(column) != null)
                name_value_pairs.set(column, values[Util.indexOf(columns, column)]);
            request.db.insert(table, name_value_pairs);
            l = br.readLine();
        }
        br.close();
    }
}
Also used : HTMLWriter(web.HTMLWriter) Table(web.Table) JDBCTable(db.JDBCTable) NameValuePairs(db.NameValuePairs) Form(db.Form) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader)

Aggregations

HTMLWriter (web.HTMLWriter)109 Select (db.Select)18 SQLException (java.sql.SQLException)16 ResultSet (java.sql.ResultSet)14 Table (web.Table)12 JDBCTable (db.JDBCTable)10 Person (app.Person)7 Calendar (java.util.Calendar)7 ArrayList (java.util.ArrayList)6 JDBCColumn (db.JDBCColumn)5 View (db.View)5 DBObject (db.DBObject)4 Form (db.Form)4 File (java.io.File)4 AdminTask (web.AdminTask)4 FilePathStringBuilder (web.FilePathStringBuilder)4 Select (web.Select)4 Mode (db.View.Mode)3 IOException (java.io.IOException)3 NumberFormat (java.text.NumberFormat)3