diff --git a/lua/django/input.lua b/lua/django/input.lua index 2d0aefa..90c3b35 100644 --- a/lua/django/input.lua +++ b/lua/django/input.lua @@ -31,6 +31,10 @@ local defaults = { }, border = { style = 'rounded', + text = { + top="", + top_align="left" + } }, win_options = { winhighlight = 'Normal:Normal,FloatBorder:FloatBorder', @@ -99,8 +103,14 @@ M.setup = function(config, input_opts, callback) } end -M.open = function(opts, callback) - local ui = M.setup(state.user_opts, opts, callback) +M.open = function(opts, popup_opts, callback) + local pop_opts = defaults.popup + state.user_opts = {} + if popup_opts ~= nil or popup_opts == {} then + pop_opts = popup_opts + end + local state_user_opts = fn.merge(state.user_opts, pop_opts) + local ui = M.setup(state_user_opts, opts, callback) fn.check_nvim() M.inp = require('nui.input')(ui.popup, ui.input) diff --git a/lua/django/mappings.lua b/lua/django/mappings.lua index b93c65b..f8601b2 100644 --- a/lua/django/mappings.lua +++ b/lua/django/mappings.lua @@ -9,6 +9,20 @@ local mappings = { end, desc = "create app", }, + ["jd"] = { + function() + django.dump_data() + end, + desc = "dump data", + }, + ["jo"] = { + function() + django.load_data() + end, + desc = "load data", + }, + + ["jp"] = { function() django.create_package() diff --git a/lua/django/utils.lua b/lua/django/utils.lua index 5b73cf4..b6b8323 100644 --- a/lua/django/utils.lua +++ b/lua/django/utils.lua @@ -185,11 +185,11 @@ local function env_ip(ip) end function M.create_app() - inp.open({ prompt = "create app: " }, perform_create_app) + inp.open({ prompt = "create app: " },{},perform_create_app) end function M.create_package() - inp.open({ prompt = "create package: " }, perform_create_package) + inp.open({ prompt = "create package: " },{}, perform_create_package) end function M.create_env_file(opts) @@ -283,5 +283,35 @@ function M.compile_messages() toggleterm.exec("./manage.py compilemessages", term_num, 100, ".", "float", "compile_messages", false) end +local function perform_dump_data(value) + local term_num = 13 + toggleterm.exec( + "./manage.py dumpdata --natural-foreign --natural-primary -e contenttypes -e auth.Permission -e sessions.session -e admin.logentry --indent 2 > " .. value .. ".json", + term_num, + 100, + ".", + "float", + "dump_data", + false + ) +end + +local function perform_load_data(value) + local term_num = 14 + toggleterm.exec("./manage.py loaddata" .. value .. ".json", term_num, 100, ".", "float", "load_data", false) +end + +function M.dump_data() + inp.open({ prompt = "name: ", default_value ="dump_db"}, + {popup = {border = {text = {top ="Dump data", top_align="left"}}}}, + perform_dump_data) +end + +function M.load_data() + inp.open({ prompt = "name: ", default_value = "dump_db"}, + { popup = {border = {text = {top ="Load data", top_align="left"}}}}, + perform_load_data) +end + return M