You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2015/12/17 20:21:52 UTC
[05/50] [abbrv] allura git commit: [#7919] remove sidebar & admin
widgets support
[#7919] remove sidebar & admin widgets support
Only wiki used it and we want to minimize EasyWidget usage.
Create page works with regular admin_modal style, from any page.
Subscribe only really needs to be in sidebar, not admin menu.
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/2d33fe30
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/2d33fe30
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/2d33fe30
Branch: refs/heads/db/8034
Commit: 2d33fe307524d601ab04e8cf5c6bd5b78837bf86
Parents: 2457032
Author: Dave Brondsema <da...@brondsema.net>
Authored: Wed Dec 2 10:51:03 2015 -0500
Committer: Heith Seewald <he...@gmail.com>
Committed: Wed Dec 16 13:54:30 2015 -0600
----------------------------------------------------------------------
Allura/allura/app.py | 14 ----
.../ext/admin/templates/project_tools.html | 3 -
.../lib/widgets/resources/js/admin_modal.js | 38 ---------
Allura/allura/public/nf/js/admin_modal.js | 38 +++++++++
.../templates/jinja_master/sidebar_menu.html | 5 --
.../templates/wiki/admin_add_page.html | 2 +-
.../templates/wiki/create_page_widget.html | 25 ------
.../templates/wiki/wiki_subscribe_form.html | 27 -------
.../forgewiki/tests/functional/test_rest.py | 2 +-
.../forgewiki/tests/functional/test_root.py | 12 +--
ForgeWiki/forgewiki/widgets/wiki.py | 49 ------------
ForgeWiki/forgewiki/wiki_main.py | 83 +++++++++-----------
12 files changed, 85 insertions(+), 213 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/2d33fe30/Allura/allura/app.py
----------------------------------------------------------------------
diff --git a/Allura/allura/app.py b/Allura/allura/app.py
index 621ea37..c392eae 100644
--- a/Allura/allura/app.py
+++ b/Allura/allura/app.py
@@ -602,13 +602,6 @@ class Application(object):
"""
return ""
- def sidebar_menu_widgets(self):
- """Return widgets needed by the sidebar menu of this Application.
-
- :return: a list of widgets
- """
- return []
-
@LazyProperty
def _webhooks(self):
"""A list of webhooks that can be triggered by this app.
@@ -678,13 +671,6 @@ class Application(object):
'data-mount-point': self.config.options.mount_point,
})
- def admin_menu_widgets(self):
- """Return widgets needed by the admin menu of this Application.
-
- :return: a list of widgets
- """
- return []
-
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/2d33fe30/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 ec83e0a..aa825f1 100644
--- a/Allura/allura/ext/admin/templates/project_tools.html
+++ b/Allura/allura/ext/admin/templates/project_tools.html
@@ -94,9 +94,6 @@
</ul>
{# for ordering #}
<input type="hidden" class="mount_point" value="{{mount['ac'].options.mount_point}}"/>
- {% for w in app.admin_menu_widgets() %}
- {{ w.display() }}
- {% endfor %}
</div>
{% endif %}
{% if 'sub' in mount and not mount['sub'].deleted %}
http://git-wip-us.apache.org/repos/asf/allura/blob/2d33fe30/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
deleted file mode 100644
index f796bc9..0000000
--- a/Allura/allura/lib/widgets/resources/js/admin_modal.js
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- 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 $popup_title = $('#admin_modal_title');
- var $popup_contents = $('#admin_modal_contents');
- $('body').on('click', 'a.admin_modal', function(e) {
- e.preventDefault();
- var link = this;
- $popup_title.html('');
- $popup_contents.html('Loading...');
- $.get(link.href, function (data) {
- $popup_title.html($(link).html());
- $popup_contents.html(data);
- var csrf_exists = $popup_contents.find('form > input[name="_session_id"]').length;
- if (!csrf_exists) {
- var cval = $.cookie('_session_id');
- var csrf_input = $('<input name="_session_id" type="hidden" value="'+cval+'">');
- $popup_contents.find('form').append(csrf_input);
- }
- });
- });
-});
http://git-wip-us.apache.org/repos/asf/allura/blob/2d33fe30/Allura/allura/public/nf/js/admin_modal.js
----------------------------------------------------------------------
diff --git a/Allura/allura/public/nf/js/admin_modal.js b/Allura/allura/public/nf/js/admin_modal.js
new file mode 100644
index 0000000..f796bc9
--- /dev/null
+++ b/Allura/allura/public/nf/js/admin_modal.js
@@ -0,0 +1,38 @@
+/*
+ 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 $popup_title = $('#admin_modal_title');
+ var $popup_contents = $('#admin_modal_contents');
+ $('body').on('click', 'a.admin_modal', function(e) {
+ e.preventDefault();
+ var link = this;
+ $popup_title.html('');
+ $popup_contents.html('Loading...');
+ $.get(link.href, function (data) {
+ $popup_title.html($(link).html());
+ $popup_contents.html(data);
+ var csrf_exists = $popup_contents.find('form > input[name="_session_id"]').length;
+ if (!csrf_exists) {
+ var cval = $.cookie('_session_id');
+ var csrf_input = $('<input name="_session_id" type="hidden" value="'+cval+'">');
+ $popup_contents.find('form').append(csrf_input);
+ }
+ });
+ });
+});
http://git-wip-us.apache.org/repos/asf/allura/blob/2d33fe30/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 9572cda..2cb433a 100644
--- a/Allura/allura/templates/jinja_master/sidebar_menu.html
+++ b/Allura/allura/templates/jinja_master/sidebar_menu.html
@@ -92,11 +92,6 @@
</ul>
{% do ul_active.append(False) %}
{% endif %}
- {% if c.app and c.app.sidebar_menu_widgets() %}
- {% for w in c.app.sidebar_menu_widgets() %}
- {{ w.display() }}
- {% endfor %}
- {% endif %}
{% if c.app and c.app.sidebar_menu_js() %}
<script>
{{c.app.sidebar_menu_js()|safe}}
http://git-wip-us.apache.org/repos/asf/allura/blob/2d33fe30/ForgeWiki/forgewiki/templates/wiki/admin_add_page.html
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/templates/wiki/admin_add_page.html b/ForgeWiki/forgewiki/templates/wiki/admin_add_page.html
index 6055747..ae3c0aa 100644
--- a/ForgeWiki/forgewiki/templates/wiki/admin_add_page.html
+++ b/ForgeWiki/forgewiki/templates/wiki/admin_add_page.html
@@ -20,7 +20,7 @@
$(function () {
$("form").submit(function () {
location.href = '{{ app.url }}' +
- encodeURIComponent($('input[name=name]', $(this)).val().replace('/', '-')) + '/edit';
+ encodeURIComponent($('input[name=name]', $(this)).val().replace(new RegExp('/', 'g'), '-')) + '/edit';
return false;
});
});
http://git-wip-us.apache.org/repos/asf/allura/blob/2d33fe30/ForgeWiki/forgewiki/templates/wiki/create_page_widget.html
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/templates/wiki/create_page_widget.html b/ForgeWiki/forgewiki/templates/wiki/create_page_widget.html
deleted file mode 100644
index 43ab051..0000000
--- a/ForgeWiki/forgewiki/templates/wiki/create_page_widget.html
+++ /dev/null
@@ -1,25 +0,0 @@
-{#-
- 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.
--#}
-<h1>Add a Wiki Page</h1>
-<form class="grid-10">
- <label class="grid-2">Name</label>
- <div class="grid-7"><input type="text" name="name"></div>
- <label class="grid-2"> </label>
- <div class="grid-7"><input type="submit" value="Create page"></div>
-</form>
http://git-wip-us.apache.org/repos/asf/allura/blob/2d33fe30/ForgeWiki/forgewiki/templates/wiki/wiki_subscribe_form.html
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/templates/wiki/wiki_subscribe_form.html b/ForgeWiki/forgewiki/templates/wiki/wiki_subscribe_form.html
deleted file mode 100644
index 9ac328e..0000000
--- a/ForgeWiki/forgewiki/templates/wiki/wiki_subscribe_form.html
+++ /dev/null
@@ -1,27 +0,0 @@
-{#-
- 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 %}
-<form action="{{action}}" id="wiki_subscribe_form" class="hidden" method="POST">
- {% if subscribed %}
- <input type="hidden" name="unsubscribe" value="1">
- {% else %}
- <input type="hidden" name="subscribe" value="1">
- {% endif %}
- {{lib.csrf_token()}}
-</form>
http://git-wip-us.apache.org/repos/asf/allura/blob/2d33fe30/ForgeWiki/forgewiki/tests/functional/test_rest.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/tests/functional/test_rest.py b/ForgeWiki/forgewiki/tests/functional/test_rest.py
index 4aba7f1..85602c7 100644
--- a/ForgeWiki/forgewiki/tests/functional/test_rest.py
+++ b/ForgeWiki/forgewiki/tests/functional/test_rest.py
@@ -42,7 +42,7 @@ class TestWikiApi(TestRestApiBase):
def test_get_page(self):
r = self.app.get('/p/test/wiki/Home/')
- discussion_url = r.html.findAll('form')[5]['action'][:-4]
+ discussion_url = r.html.find('form', id='edit_post')['action'][:-4]
content = file(__file__).read()
self.app.post('/wiki/Home/attach',
upload_files=[('file_info', 'test_root.py', content)])
http://git-wip-us.apache.org/repos/asf/allura/blob/2d33fe30/ForgeWiki/forgewiki/tests/functional/test_root.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/tests/functional/test_root.py b/ForgeWiki/forgewiki/tests/functional/test_root.py
index 9a88fd1..1afcfd3 100644
--- a/ForgeWiki/forgewiki/tests/functional/test_root.py
+++ b/ForgeWiki/forgewiki/tests/functional/test_root.py
@@ -756,24 +756,24 @@ class TestRootController(TestController):
# user is not subscribed
assert not M.Mailbox.subscribed(user_id=user._id)
r = self.app.get('/p/test/wiki/Home/', extra_environ={'username': str(user.username)})
- inp = r.html.find('input', {'type': 'hidden', 'name': 'subscribe'})
- assert inp is not None
+ sidebar_menu = r.html.find('div', attrs={'id': 'sidebar'})
+ assert 'Subscribe to wiki' in str(sidebar_menu)
# subscribe
self.app.post('/p/test/wiki/subscribe', {'subscribe': True},
extra_environ={'username': str(user.username)}).follow()
# user is subscribed
assert M.Mailbox.subscribed(user_id=user._id)
r = self.app.get('/p/test/wiki/Home/', extra_environ={'username': str(user.username)})
- inp = r.html.find('input', {'type': 'hidden', 'name': 'unsubscribe'})
- assert inp is not None
+ sidebar_menu = r.html.find('div', attrs={'id': 'sidebar'})
+ assert 'Unsubscribe' in str(sidebar_menu)
# unsubscribe
self.app.post('/p/test/wiki/subscribe', {'unsubscribe': True},
extra_environ={'username': str(user.username)}).follow()
# user is not subscribed
assert not M.Mailbox.subscribed(user_id=user._id)
r = self.app.get('/p/test/wiki/Home/', extra_environ={'username': str(user.username)})
- inp = r.html.find('input', {'type': 'hidden', 'name': 'subscribe'})
- assert inp is not None
+ sidebar_menu = r.html.find('div', attrs={'id': 'sidebar'})
+ assert 'Subscribe to wiki' in str(sidebar_menu)
def test_rate_limit_new_page(self):
# Set rate limit to unlimit
http://git-wip-us.apache.org/repos/asf/allura/blob/2d33fe30/ForgeWiki/forgewiki/widgets/wiki.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/widgets/wiki.py b/ForgeWiki/forgewiki/widgets/wiki.py
deleted file mode 100644
index ffd2727..0000000
--- a/ForgeWiki/forgewiki/widgets/wiki.py
+++ /dev/null
@@ -1,49 +0,0 @@
-# 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
-from allura.lib.widgets.forms import ForgeForm
-
-
-class CreatePageWidget(ffw.Lightbox):
- content_template='forgewiki:templates/wiki/create_page_widget.html'
-
- def resources(self):
- for r in super(CreatePageWidget, self).resources():
- yield r
- yield ew.JSScript('''$(function () {
- $('#lightbox_create_wiki_page form').submit(function(){
- location.href = $('#sidebar a.add_wiki_page').attr('href') +
- encodeURIComponent($('input[name=name]', $(this)).val().replace('/', '-')) + '/edit';
- return false;
- });
- });''')
-
-
-class WikiSubscribeForm(ForgeForm):
- template='jinja:forgewiki:templates/wiki/wiki_subscribe_form.html'
- defaults = dict(ForgeForm.defaults, subscribed=False)
-
- def resources(self):
- for r in super(WikiSubscribeForm, self).resources():
- yield r
- yield ew.JSScript("""
- $('a[href$="#toggle-subscribe"]').click(function() {
- $('#wiki_subscribe_form').submit();
- return false;
- })""")
http://git-wip-us.apache.org/repos/asf/allura/blob/2d33fe30/ForgeWiki/forgewiki/wiki_main.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/wiki_main.py b/ForgeWiki/forgewiki/wiki_main.py
index b08d03e..181399b 100644
--- a/ForgeWiki/forgewiki/wiki_main.py
+++ b/ForgeWiki/forgewiki/wiki_main.py
@@ -51,7 +51,6 @@ from allura.lib.widgets.search import SearchResults, SearchHelp
# Local imports
from forgewiki import model as WM
from forgewiki import version
-from forgewiki.widgets.wiki import CreatePageWidget, WikiSubscribeForm
log = logging.getLogger(__name__)
@@ -60,8 +59,6 @@ class W:
thread = w.Thread(
page=None, limit=None, page_size=None, count=None,
style='linear')
- create_page_lightbox = CreatePageWidget(
- name='create_wiki_page', trigger='#sidebar a.add_wiki_page')
markdown_editor = ffw.MarkdownEdit()
confirmation = ffw.Lightbox(name='confirm',
trigger='a.post-link',
@@ -217,16 +214,12 @@ The wiki uses [Markdown](%s) syntax.
return [
SitemapEntry(menu_id, '.')[SitemapEntry('Pages')[pages]]]
- def create_common_wiki_menu(self,
- has_create_access,
- create_page_url,
- create_page_class,
- admin_menu=False):
+ def create_common_wiki_menu(self, has_create_access, admin_menu=False):
links = []
if has_create_access:
- links += [SitemapEntry('Create Page', create_page_url,
+ links += [SitemapEntry('Create Page', self.admin_url + 'create_wiki_page',
ui_icon=g.icons['add'],
- className=create_page_class)]
+ className='admin_modal')]
if not admin_menu:
links += [SitemapEntry(''),
SitemapEntry('Wiki Home', self.url, className='wiki_home')]
@@ -243,15 +236,14 @@ The wiki uses [Markdown](%s) syntax.
SitemapEntry(
'Moderate', discussion.url() + 'moderate', ui_icon=g.icons['moderate'],
small=pending_mod_count))
- if not c.user.is_anonymous():
+ if not c.user.is_anonymous() and not admin_menu:
subscribed = M.Mailbox.subscribed(app_config_id=self.config._id)
subscribe_action = 'unsubscribe' if subscribed else 'subscribe'
subscribe_title = '{}{}'.format(
subscribe_action.capitalize(),
'' if subscribed else ' to wiki')
- subscribe_url = '{}#toggle-subscribe'.format(self.url)
- if not admin_menu:
- links.append(SitemapEntry(None))
+ subscribe_url = '{}#toggle-{}'.format(self.url + 'subscribe', subscribe_action)
+ links.append(SitemapEntry(None))
links.append(SitemapEntry(subscribe_title, subscribe_url, ui_icon=g.icons['mail']))
if not admin_menu:
links += [SitemapEntry(''),
@@ -259,46 +251,49 @@ The wiki uses [Markdown](%s) syntax.
return links
def admin_menu(self, skip_common_menu=False):
- admin_url = c.project.url() + \
- 'admin/' + \
- self.config.options.mount_point + '/'
links = [SitemapEntry('Set Home',
- admin_url + 'home',
+ self.admin_url + 'home',
className='admin_modal')]
if not self.show_left_bar and not skip_common_menu:
- links += self.create_common_wiki_menu(True,
- admin_url +
- 'create_wiki_page',
- 'admin_modal', admin_menu=True)
+ links += self.create_common_wiki_menu(has_create_access=True, admin_menu=True)
links += super(ForgeWikiApp, self).admin_menu(force_options=True)
return links
@h.exceptionless([], log)
- def admin_menu_widgets(self):
- widgets = super(ForgeWikiApp, self).admin_menu_widgets()
- if not c.user.is_anonymous():
- form = WikiSubscribeForm(
- action=self.url + 'subscribe',
- subscribed=M.Mailbox.subscribed(app_config_id=self.config._id))
- widgets.append(form)
- return widgets
-
- @h.exceptionless([], log)
def sidebar_menu(self):
- return self.create_common_wiki_menu(has_access(self, 'create'), c.app.url, 'add_wiki_page')
-
- @h.exceptionless([], log)
- def sidebar_menu_widgets(self):
- widgets = super(ForgeWikiApp, self).sidebar_menu_widgets()
- widgets.append(W.create_page_lightbox)
- if not c.user.is_anonymous():
- form = WikiSubscribeForm(
- action=self.url + 'subscribe',
- subscribed=M.Mailbox.subscribed())
- widgets.append(form)
- return widgets
+ return self.create_common_wiki_menu(has_create_access=has_access(self, 'create'))
+
+ def sidebar_menu_js(self):
+ return '''
+ $('#sidebar').on('click', 'a[href$="#toggle-subscribe"]', function(e) {
+ e.preventDefault();
+ var link = this;
+ var data = {
+ _session_id: $.cookie('_session_id'),
+ subscribe: '1',
+ }
+ $.post(this.href, data, function(){
+ $('#messages').notify('Subscribed to wiki.');
+ $('span', link).text('Unsubscribe');
+ $(link).attr('href', $(link).attr('href').replace('-subscribe','-unsubscribe'));
+ });
+ });
+ $('#sidebar').on('click', 'a[href$="#toggle-unsubscribe"]', function(e) {
+ e.preventDefault();
+ var link = this;
+ var data = {
+ _session_id: $.cookie('_session_id'),
+ unsubscribe: '1',
+ }
+ $.post(this.href, data, function(){
+ $('#messages').notify('Unsubscribed.');
+ $('span', link).text('Subscribe to wiki');
+ $(link).attr('href', $(link).attr('href').replace('-unsubscribe','-subscribe'));
+ });
+ });
+ '''
def install(self, project):
'Set up any default permissions and roles here'