From b61b0bf3ad1a80b1ab3ec7e65e206b24f0de01e6 Mon Sep 17 00:00:00 2001 From: ilvalle Date: Thu, 5 Dec 2013 11:43:23 +0100 Subject: [PATCH 1/3] todo panel in admin editor --- applications/admin/controllers/default.py | 31 +++++++++++++++++++ .../admin/static/css/web2py-codemirror.css | 13 ++++++++ applications/admin/views/default/edit.html | 28 +++++++++++++++++ applications/admin/views/layout.html | 2 ++ 4 files changed, 74 insertions(+) diff --git a/applications/admin/controllers/default.py b/applications/admin/controllers/default.py index 221458de..aa95bb88 100644 --- a/applications/admin/controllers/default.py +++ b/applications/admin/controllers/default.py @@ -773,6 +773,37 @@ def edit(): else: return response.json(file_details) +def todolist(): + """ Returns all TODO of the requested app + """ + app = request.vars.app or '' + app_path = apath('%(app)s' % {'app':app}, r=request) + dirs=['models', 'controllers', 'modules', 'private' ] + def listfiles(app, dir, regexp='.*\.py$'): + files = sorted( listdir(apath('%(app)s/%(dir)s/' % {'app':app, 'dir':dir}, r=request), regexp)) + files = [x.replace(os.path.sep, '/') for x in files if not x.endswith('.bak')] + return files + + pattern = '#(todo)+\s+(.*)' + regex = re.compile(pattern, re.IGNORECASE) + + output = [] + for d in dirs: + for f in listfiles(app, d): + matches = [] + filename= apath(os.path.join(app, d, f), r=request) + + with open(filename, 'r') as f_s: + src = f_s.read() + for m in regex.finditer(src): + start = m.start() + lineno = src.count('\n', 0, start) + 1 + matches.append({'text':m.group(0), 'lineno':lineno}) + if len(matches) != 0: + output.append({'filename':f,'matches':matches, 'dir':d}) + + return {'todo':output, 'app': app} + def resolve(): """ diff --git a/applications/admin/static/css/web2py-codemirror.css b/applications/admin/static/css/web2py-codemirror.css index a11e8d88..f5f80211 100644 --- a/applications/admin/static/css/web2py-codemirror.css +++ b/applications/admin/static/css/web2py-codemirror.css @@ -1,3 +1,4 @@ +/* TODO rename this file as web2py-editor.css */ /* Fullscreen */ .CodeMirror-fullscreen { z-index: 1030; @@ -36,3 +37,15 @@ /*.nav-tabs>li { min-width: 100px; }*/ + +#windows_divs > div { + position: fixed; + height: 30%; + left: 0; + background: white; + right: 0; + bottom: 41px; + z-index: 1030; + overflow: inherit; + border-top: 1px solid #ddd; +} diff --git a/applications/admin/views/default/edit.html b/applications/admin/views/default/edit.html index 9187a4c4..15ab9317 100644 --- a/applications/admin/views/default/edit.html +++ b/applications/admin/views/default/edit.html @@ -227,7 +227,35 @@ $(document).on('click', 'a.font_button', function (e) {
+
+
+ {{=LOAD('default', 'todolist.load', vars={'app':app}, ajax=True, timeout=60000, times="infinity")}} +
+
+{{block footer}} + + + +{{end}} diff --git a/applications/admin/views/default/edit_js.html b/applications/admin/views/default/edit_js.html index 62e6fb54..51bd27ef 100644 --- a/applications/admin/views/default/edit_js.html +++ b/applications/admin/views/default/edit_js.html @@ -74,15 +74,15 @@ request.env['wsgi_url_scheme'], request.env['http_host'], URL(c='debug', f='toggle_breakpoint')))}}, sel); }); - function makeMarker() { - var marker = document.createElement("div"); - marker.style.color = "#822"; - marker.innerHTML = "●"; - marker.className = "breakpoint"; - return marker; - } + function makeMarker() { + var marker = document.createElement("div"); + marker.style.color = "#822"; + marker.innerHTML = "●"; + marker.className = "breakpoint"; + return marker; + } - {{if filetype in ('html', 'javascript', 'css'):}} + {{if filetype in ('html', 'javascript', 'css'):}} // must be here or break emmet/zencoding CodeMirror.defaults.extraKeys["Ctrl-S"] = function(instance) { @@ -94,26 +94,26 @@ CodeMirror.defaults.extraKeys["Shift-Esc"] = function(cm) { if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false); } - {{pass}} - {{if filetype=='python':}} - // must be here or break emmet/zencoding for python - CodeMirror.defaults.extraKeys["Ctrl-S"] = - function(instance) { - doClickSave();}; - CodeMirror.defaults.extraKeys["Ctrl-Space"] = "autocomplete"; - CodeMirror.defaults.extraKeys["Tab"] = "indentMore"; - CodeMirror.defaults.extraKeys["Shift-Tab"] = "indentLess"; - CodeMirror.defaults.extraKeys["Ctrl-F11"] = function(cm) { - cm.setOption("fullScreen", !cm.getOption("fullScreen")); - }, - CodeMirror.defaults.extraKeys["Shift-Esc"] = function(cm) { - if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false); - } - //for autocomplete - CodeMirror.commands.autocomplete = function(cm) { - CodeMirror.showHint(cm, CodeMirror.pythonHint); - } - {{pass}} + {{pass}} + {{if filetype=='python':}} + // must be here or break emmet/zencoding for python + CodeMirror.defaults.extraKeys["Ctrl-S"] = + function(instance) { + doClickSave();}; + CodeMirror.defaults.extraKeys["Ctrl-Space"] = "autocomplete"; + CodeMirror.defaults.extraKeys["Tab"] = "indentMore"; + CodeMirror.defaults.extraKeys["Shift-Tab"] = "indentLess"; + CodeMirror.defaults.extraKeys["Ctrl-F11"] = function(cm) { + cm.setOption("fullScreen", !cm.getOption("fullScreen")); + }, + CodeMirror.defaults.extraKeys["Shift-Esc"] = function(cm) { + if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false); + } + //for autocomplete + CodeMirror.commands.autocomplete = function(cm) { + CodeMirror.showHint(cm, CodeMirror.pythonHint); + } + {{pass}} store_changes_function = function(instance, changeObj) { jQuery(instance).data('saved', false); instance.off("change", store_changes_function); @@ -128,6 +128,19 @@ request.env['wsgi_url_scheme'], request.env['http_host'], URL(c='debug', f='list_breakpoints')))}}, editor); + // TODO move it in a separated file + CodeMirror.defineExtension("centerOnCursor", function(limit) { + var coords = this.cursorCoords(null, "local"); + if (this.getScrollerElement().clientHeight === 0 && limit !== 10) { + if (limit === undefined) limit = 1; + else limit += 1; + editor = this; + setTimeout(function() {editor.centerOnCursor()}, 100); + return; + } + clientHeight = (this.getScrollerElement().clientHeight / 2) + this.scrollTo(null, (coords.top + coords.bottom)/2 - 10); + });
diff --git a/applications/admin/views/default/todolist.load b/applications/admin/views/default/todolist.load index 6d5bf494..00aceb92 100644 --- a/applications/admin/views/default/todolist.load +++ b/applications/admin/views/default/todolist.load @@ -7,7 +7,7 @@
  • {{=file['filename']}} ({{=len(file['matches'])}} TODO)
  • {{pass}}