From: Nicolas Boisselier Date: Thu, 5 Sep 2024 22:38:41 +0000 (+0200) Subject: bin/dbq-vi X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=320ae788c28ce9264ed0f2d5f66dd635d9b3f3f4;p=nb.git bin/dbq-vi --- diff --git a/bin/dbq-vi b/bin/dbq-vi index 96f510ca..769ec1c0 100755 --- a/bin/dbq-vi +++ b/bin/dbq-vi @@ -1,26 +1,10 @@ #!/usr/bin/env bash -tmp=/tmp/$USER-dbq-vi-$$ - -_main() { - #exec echo $tmp - dbq.php "$1/vi/$2.sh" > "$tmp" || return - - perl -i -pe 's/(\w+=".*?") /$1\n/g; s/;\s*$/\n/ ' "$tmp" - - md5=$(md5sum "$tmp") - - vi "$tmp" - [ -s "$tmp" ] || return - [ "$md5" == "$(md5sum "$tmp")" ] && return - bash -f "$tmp" || return - #echo $md5 " == $(md5sum "$tmp")" - - eval dbq.php $1/update/ format=yaml $(cat "$tmp") - -} +tmp=/tmp/$USER-dbq-vi-$$.yaml main() { #exec echo $tmp + path="$1" + id="$2" cat < "$tmp" # # dbq-vi @@ -28,7 +12,13 @@ main() { # EOF - dbq.php "$1/vi/$2.yaml" >> "$tmp" || return + if [ -z "$id" ] + then + dbq.php "$path/add.yaml" >> "$tmp" || return + sed -i -e 's/"//g' "$tmp" + else + dbq.php "$path/vi/$id.yaml" >> "$tmp" || return + fi md5=$(md5sum "$tmp") vi "$tmp" @@ -37,7 +27,12 @@ EOF [ "$md5" == "$(md5sum "$tmp")" ] && return #echo $md5 " == $(md5sum "$tmp")" - dbq.php $1/update.yaml __YAML__="$tmp" + if [ -z "$id" ] + then + dbq.php $path/insert.yaml __YAML__="$tmp" + else + dbq.php $path/update.yaml __YAML__="$tmp" + fi } diff --git a/www/dbq/dbq.php b/www/dbq/dbq.php index 98dc6185..88d27af3 100644 --- a/www/dbq/dbq.php +++ b/www/dbq/dbq.php @@ -502,8 +502,18 @@ class DbQ extends nb { #debug([count($keys),$keys,count($values),$values]); $values = array_combine($keys,$values); + if ($add and (0 + or $this->params['format'] == 'yaml' + or $this->params['format'] == 'json' + )) { + foreach ($this->table->fields() as $field) { + $fields[$field->name] = ''; + } + $this->db->out($fields); + return; + # Handle format for /vi - if ($this->params['format'] != $this->format_html) { + } elseif ($this->params['format'] != $this->format_html) { #debug($values); $row = $this->db->query2h($this->table->html_edit_sql($values));