You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by je...@apache.org on 2015/08/13 20:07:07 UTC
[40/50] allura git commit: [#7922] Add "admin" section to the left
sidebar
[#7922] Add "admin" section to the left sidebar
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/ef7125cc
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/ef7125cc
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/ef7125cc
Branch: refs/heads/ib/7922
Commit: ef7125cc112d9afb9700a56c80ca74646d26d89c
Parents: 2f144a9
Author: Igor Bondarenko <je...@gmail.com>
Authored: Wed Jul 29 19:25:49 2015 +0300
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Thu Aug 13 18:14:42 2015 +0300
----------------------------------------------------------------------
Allura/allura/app.py | 22 +++++++++
Allura/allura/ext/admin/admin_main.py | 5 ++-
.../ext/admin/templates/project_tools.html | 44 ++++--------------
Allura/allura/lib/widgets/admin_widgets.py | 47 ++++++++++++++++++++
.../lib/widgets/resources/js/admin_modal.js | 34 ++++++++++++++
.../resources/js/admin_tool_delete_modal.js | 40 +++++++++++++++++
Allura/allura/public/nf/js/project_tools.js | 39 ----------------
.../templates/jinja_master/sidebar_menu.html | 11 +++++
.../widgets/admin_tool_delete_modal.html | 34 ++++++++++++++
9 files changed, 199 insertions(+), 77 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/ef7125cc/Allura/allura/app.py
----------------------------------------------------------------------
diff --git a/Allura/allura/app.py b/Allura/allura/app.py
index 62b82fe..3aa8aad 100644
--- a/Allura/allura/app.py
+++ b/Allura/allura/app.py
@@ -44,6 +44,7 @@ from allura import model
from allura.controllers import BaseController
from allura.lib.decorators import require_post, memoize
from allura.lib.utils import permanent_redirect, ConfigProxy
+from allura.lib.widgets import admin_widgets
from allura import model as M
log = logging.getLogger(__name__)
@@ -291,6 +292,14 @@ class Application(object):
self.admin = DefaultAdminController(self)
@LazyProperty
+ def admin_modal(self):
+ return admin_widgets.AdminModal()
+
+ @LazyProperty
+ def admin_tool_delete_modal(self):
+ return admin_widgets.AdminToolDeleteModal()
+
+ @LazyProperty
def sitemap(self):
"""Return a list of :class:`SitemapEntries <allura.app.SitemapEntry>`
describing the page hierarchy provided by this Application.
@@ -616,6 +625,19 @@ class Application(object):
links.append(SitemapEntry('Webhooks', admin_url + 'webhooks'))
return links
+ @LazyProperty
+ def admin_menu_delete_button(self):
+ anchored_tools = self.project.neighborhood.get_anchored_tools()
+ anchored = self.tool_label.lower() in anchored_tools.keys()
+ if self.uninstallable and not anchored:
+ return SitemapEntry(
+ label='Delete',
+ url='#',
+ className='admin_tool_delete_modal',
+ extra_html_attrs={
+ 'data-mount-point': self.config.options.mount_point,
+ })
+
def handle_message(self, topic, message):
"""Handle incoming email msgs addressed to this tool.
Default is a no-op.
http://git-wip-us.apache.org/repos/asf/allura/blob/ef7125cc/Allura/allura/ext/admin/admin_main.py
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/admin/admin_main.py b/Allura/allura/ext/admin/admin_main.py
index ec61edb..dcda9be 100644
--- a/Allura/allura/ext/admin/admin_main.py
+++ b/Allura/allura/ext/admin/admin_main.py
@@ -44,6 +44,7 @@ from allura.controllers import BaseController
from allura.lib.decorators import require_post
from allura.tasks import export_tasks
from allura.lib.widgets.project_list import ProjectScreenshots
+from allura.lib.widgets import admin_widgets
from . import widgets as aw
@@ -54,8 +55,8 @@ log = logging.getLogger(__name__)
class W:
markdown_editor = ffw.MarkdownEdit()
label_edit = ffw.LabelEdit()
- mount_delete = ffw.Lightbox(name='mount_delete', trigger='a.mount_delete')
- admin_modal = ffw.Lightbox(name='admin_modal', trigger='a.admin_modal')
+ admin_modal = admin_widgets.AdminModal()
+ mount_delete = admin_widgets.AdminToolDeleteModal()
install_modal = ffw.Lightbox(
name='install_modal', trigger='a.install_trig')
explain_export_modal = ffw.Lightbox(
http://git-wip-us.apache.org/repos/asf/allura/blob/ef7125cc/Allura/allura/ext/admin/templates/project_tools.html
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/admin/templates/project_tools.html b/Allura/allura/ext/admin/templates/project_tools.html
index 38705ed..c9eab4a 100644
--- a/Allura/allura/ext/admin/templates/project_tools.html
+++ b/Allura/allura/ext/admin/templates/project_tools.html
@@ -17,6 +17,7 @@
under the License.
-#}
{% extends g.theme.master %}
+{% from 'allura:templates/jinja_master/sidebar_menu.html' import sidebar_item with context %}
{% do g.register_forge_css('css/forge/deck.css') %}
{% do g.register_forge_js('js/project_tools.js', location='body_js_tail') %}
@@ -87,24 +88,9 @@
<img src="{{ g.theme.app_icon_url(app, 48) }}" alt="">
</li>
{% for link in links %}
- <li>
- <a href="{{ link.url }}" class="{{ link.className }}">{{ link.label }}</a>
- </li>
+ {{sidebar_item(link)}}
{% endfor %}
- {% if app.uninstallable and not (app.tool_label.lower() in app.project.neighborhood.get_anchored_tools().keys()) %}
- <li>
- <form method="post" action="update_mounts" id="mounts_edit_2-{{loop.index0}}">
- <input type="hidden" class="mount_point"
- name="tool-{{loop.index0}}.mount_point"
- value="{{mount['ac'].options.mount_point}}"/>
- <input name="tool-{{loop.index0}}.delete" type="hidden" value="Delete"/>
- {% if mount['ac'].load().uninstallable %}
- <a href="#" class="mount_delete" data-mount-point="{{ mount['ac'].options.mount_point }}">Delete</a>
- {% endif %}
- {{lib.csrf_token()}}
- </form>
- </li>
- {% endif %}
+ {{sidebar_item(app.admin_menu_delete_button)}}
</ul>
{% if not app.uninstallable %}
<input type="hidden" class="mount_point" value="{{mount['ac'].options.mount_point}}"/>
@@ -119,14 +105,9 @@
<img src="{{ g.theme.app_icon_url('subproject', 48) }}" alt="">
</li>
<li>
- <form method="post" action="update_mounts" id="mounts_edit_2-{{loop.index0}}">
- <input type="hidden" class="shortname"
- name="subproject-{{loop.index0}}.shortname"
- value="{{mount['sub'].shortname}}"/>
- <input name="subproject-{{loop.index0}}.delete" type="hidden" value="Delete"/>
- <a href="#" class="mount_delete" data-mount-point="{{ mount['sub'].shortname }}">Delete</a>
- {{lib.csrf_token()}}
- </form>
+ <a href="#" data-mount-point="{{ mount['sub'].shortname }}" class="admin_tool_delete_modal">
+ <span>Delete</span>
+ </a>
</li>
</ul>
</div>
@@ -137,17 +118,8 @@
<div style="clear:both">
{{c.page_list.display(page=page, limit=limit, count=total_mounts)}}
</div>
-<form id="mount_delete_form" style="display:none">
- <div class="grid-13 warning_msg">Warning: This will destroy all data in this tool and is irreversible!</div>
- <div class="grid-13"> </div>
- <hr>
- <div class="grid-13"> </div>
- <div class="grid-13">
- <input type="button" value="Delete" class="continue_delete"> <input type="button" value="Cancel" class="cancel_delete close">
- </div>
-</form>
-{{c.admin_modal.display(content='<h1 id="popup_title"></h1><div id="popup_contents"></div>')}}
-{{c.mount_delete.display(content='<h1>Confirm Delete</h1>')}}
+{{c.admin_modal.display()}}
+{{c.mount_delete.display()}}
<div><!--dummy-->
<h3 style="clear:left">Grouping</h3>
http://git-wip-us.apache.org/repos/asf/allura/blob/ef7125cc/Allura/allura/lib/widgets/admin_widgets.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/admin_widgets.py b/Allura/allura/lib/widgets/admin_widgets.py
new file mode 100644
index 0000000..249962e
--- /dev/null
+++ b/Allura/allura/lib/widgets/admin_widgets.py
@@ -0,0 +1,47 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import ew.jinja2_ew as ew
+
+from allura.lib.widgets import form_fields as ffw
+
+
+class AdminModal(ffw.Lightbox):
+ defaults = dict(
+ ffw.Lightbox.defaults,
+ name='admin_modal',
+ trigger='a.admin_modal',
+ content='<h1 id="admin_modal_title"></h1>'
+ '<div id="admin_modal_contents"></div>')
+
+ def resources(self):
+ for r in super(AdminModal, self).resources():
+ yield r
+ yield ew.JSLink('js/admin_modal.js')
+
+
+class AdminToolDeleteModal(ffw.Lightbox):
+ defaults = dict(
+ ffw.Lightbox.defaults,
+ name='admin_tool_delete_modal',
+ trigger='a.admin_tool_delete_modal',
+ content_template='allura:templates/widgets/admin_tool_delete_modal.html')
+
+ def resources(self):
+ for r in super(AdminToolDeleteModal, self).resources():
+ yield r
+ yield ew.JSLink('js/admin_tool_delete_modal.js')
http://git-wip-us.apache.org/repos/asf/allura/blob/ef7125cc/Allura/allura/lib/widgets/resources/js/admin_modal.js
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/resources/js/admin_modal.js b/Allura/allura/lib/widgets/resources/js/admin_modal.js
new file mode 100644
index 0000000..41a5264
--- /dev/null
+++ b/Allura/allura/lib/widgets/resources/js/admin_modal.js
@@ -0,0 +1,34 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+*/
+$(function() {
+ var cval = $.cookie('_session_id');
+ var csrf_input = $('<input name="_session_id" type="hidden" value="'+cval+'">');
+ var $popup_title = $('#admin_modal_title');
+ var $popup_contents = $('#admin_modal_contents');
+ $('a.admin_modal').click(function () {
+ var link = this;
+ $popup_title.html('');
+ $popup_contents.html('Loading...');
+ $.get(link.href, function (data) {
+ $popup_title.html($(link).html());
+ $popup_contents.html(data);
+ $popup_contents.find('form').append(csrf_input);
+ });
+ });
+});
http://git-wip-us.apache.org/repos/asf/allura/blob/ef7125cc/Allura/allura/lib/widgets/resources/js/admin_tool_delete_modal.js
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/resources/js/admin_tool_delete_modal.js b/Allura/allura/lib/widgets/resources/js/admin_tool_delete_modal.js
new file mode 100644
index 0000000..3d41261
--- /dev/null
+++ b/Allura/allura/lib/widgets/resources/js/admin_tool_delete_modal.js
@@ -0,0 +1,40 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+*/
+$(function() {
+ var $form = $('#admin-tool-delete-modal-form');
+ $('a.admin_tool_delete_modal').click(function() {
+ var mount_point = $(this).data('mount-point');
+ $form.find('.mount_point').val(mount_point);
+ var tool_label = 'this';
+ if (mount_point) {
+ tool_label = 'the "' + mount_point + '"';
+ }
+ var msg = 'Warning: This will destroy all data in ';
+ msg += tool_label;
+ msg += ' tool and is irreversible!';
+ $form.find('.warning-msg').text(msg);
+ });
+ $form.find('.delete-tool').click(function() {
+ if ($form.find('.mount_point').val()) {
+ $form.submit();
+ } else {
+ console.log('Do not know which tool to delete!');
+ }
+ });
+});
http://git-wip-us.apache.org/repos/asf/allura/blob/ef7125cc/Allura/allura/public/nf/js/project_tools.js
----------------------------------------------------------------------
diff --git a/Allura/allura/public/nf/js/project_tools.js b/Allura/allura/public/nf/js/project_tools.js
index a690937..c235f05 100644
--- a/Allura/allura/public/nf/js/project_tools.js
+++ b/Allura/allura/public/nf/js/project_tools.js
@@ -18,9 +18,6 @@
*/
(function() {
- // Provide CSRF protection
- var cval = $.cookie('_session_id');
- var csrf_input = $('<input name="_session_id" type="hidden" value="'+cval+'">');
// Install popup
var install_popup = $('#lightbox_install_modal');
var install_form = $('#install_form');
@@ -50,42 +47,6 @@
new_mount_label.val('');
}
});
- // Edit popup
- var $popup_title = $('#popup_title');
- var $popup_contents = $('#popup_contents');
- $('a.admin_modal').click(function () {
- var link = this;
- $popup_title.html('');
- $popup_contents.html('Loading...');
- $.get(link.href, function (data) {
- $popup_title.html($(link).html());
- $popup_contents.html(data);
- $popup_contents.find('form').append(csrf_input);
- });
- });
- // delete popup
- var form_to_delete = null;
- var mount_delete_popup = $('#lightbox_mount_delete');
- var mount_delete_form = $('#mount_delete_form');
- mount_delete_popup.append(mount_delete_form.show());
- mount_delete_form.find('.continue_delete').click(function () {
- form_to_delete.submit();
- form_to_delete = null;
- });
- mount_delete_form.find('.cancel_delete').click(function () {
- form_to_delete = null;
- });
- $('a.mount_delete').click(function () {
- var tool_label = 'this';
- var mount_point = $(this).data('mount-point');
- if (mount_point) {
- tool_label = 'the "' + mount_point + '"';
- }
- $('div.warning_msg').text('Warning: This will destroy all data in ' + tool_label + ' tool and is irreversible!');
-
- form_to_delete = this.parentNode;
- return false;
- });
// sorting
$('#sortable').sortable({items: ".fleft:not(.isnt_sorted)"}).bind( "sortupdate", function (e) {
var sortables = $('#sortable .fleft');
http://git-wip-us.apache.org/repos/asf/allura/blob/ef7125cc/Allura/allura/templates/jinja_master/sidebar_menu.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/jinja_master/sidebar_menu.html b/Allura/allura/templates/jinja_master/sidebar_menu.html
index b51a15b..9a81035 100644
--- a/Allura/allura/templates/jinja_master/sidebar_menu.html
+++ b/Allura/allura/templates/jinja_master/sidebar_menu.html
@@ -54,6 +54,17 @@
{% endfor %}
{% endif %}
{% if c.app %}
+ {% if h.has_access(c.app, 'admin')() %}
+ {% for s in c.app.admin_menu() %}
+ {{sidebar_item(s)}}
+ {% endfor %}
+ {{sidebar_item(c.app.admin_menu_delete_button)}}
+ {{sidebar_item(None)}}
+ {{c.app.admin_modal.display()}}
+ {% if c.app.admin_menu_delete_button %}
+ {{c.app.admin_tool_delete_modal.display()}}
+ {% endif %}
+ {% endif %}
{% for s in c.app.sidebar_menu() %}
{{sidebar_item(s)}}
{% endfor %}
http://git-wip-us.apache.org/repos/asf/allura/blob/ef7125cc/Allura/allura/templates/widgets/admin_tool_delete_modal.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/widgets/admin_tool_delete_modal.html b/Allura/allura/templates/widgets/admin_tool_delete_modal.html
new file mode 100644
index 0000000..dd8aab4
--- /dev/null
+++ b/Allura/allura/templates/widgets/admin_tool_delete_modal.html
@@ -0,0 +1,34 @@
+{#-
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-#}
+{% import 'allura:templates/jinja_master/lib.html' as lib with context %}
+
+<h1>Confirm Delete</h1>
+<form method="POST"
+ action="{{c.project.url()}}admin/update_mounts"
+ id="admin-tool-delete-modal-form">
+<p class="warning-msg">Warning: This will destroy all data in this tool and is irreversible!</p>
+<hr>
+<p>
+ <input type="button" value="Delete" class="delete-tool">
+ <input type="button" value="Cancel" class="close">
+</p>
+<input type="hidden" class="mount_point" name="tool-0.mount_point"/>
+<input name="tool-0.delete" type="hidden" value="Delete"/>
+{{lib.csrf_token()}}
+</form>