You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2013/07/22 16:31:32 UTC

[1/2] git commit: [#4887] Added license header to screenshot js/css files

Updated Branches:
  refs/heads/master 0e8c64712 -> d971b6c60


[#4887] Added license header to screenshot js/css files

Signed-off-by: Cory Johns <cj...@slashdotmedia.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/d971b6c6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/d971b6c6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/d971b6c6

Branch: refs/heads/master
Commit: d971b6c60b42535b31ed46f4c51122c39501ee14
Parents: fca6878
Author: Cory Johns <cj...@slashdotmedia.com>
Authored: Mon Jul 22 14:30:48 2013 +0000
Committer: Cory Johns <cj...@slashdotmedia.com>
Committed: Mon Jul 22 14:31:07 2013 +0000

----------------------------------------------------------------------
 .../lib/widgets/resources/css/screenshots.css     | 18 ++++++++++++++++++
 .../lib/widgets/resources/js/screenshots.js       | 18 ++++++++++++++++++
 2 files changed, 36 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d971b6c6/Allura/allura/lib/widgets/resources/css/screenshots.css
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/resources/css/screenshots.css b/Allura/allura/lib/widgets/resources/css/screenshots.css
index 08be2aa..7c28adf 100644
--- a/Allura/allura/lib/widgets/resources/css/screenshots.css
+++ b/Allura/allura/lib/widgets/resources/css/screenshots.css
@@ -1,3 +1,21 @@
+/*
+       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.
+ */
 .sortable {
     float: left;
 }

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d971b6c6/Allura/allura/lib/widgets/resources/js/screenshots.js
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/resources/js/screenshots.js b/Allura/allura/lib/widgets/resources/js/screenshots.js
index 032a17c..214393b 100644
--- a/Allura/allura/lib/widgets/resources/js/screenshots.js
+++ b/Allura/allura/lib/widgets/resources/js/screenshots.js
@@ -1,3 +1,21 @@
+/*
+       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() {
   $('.sortable').sortable({cursor: 'move'}).bind('sortupdate', function(e) {
     var params = {'_session_id': $.cookie('_session_id')};


[2/2] git commit: [#4887] Screenshot sorting

Posted by jo...@apache.org.
[#4887] Screenshot sorting

Signed-off-by: Tim Van Steenburgh <tv...@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/fca6878b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/fca6878b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/fca6878b

Branch: refs/heads/master
Commit: fca6878b19ee49b97a7d853954ca0408631ca9d6
Parents: 0e8c647
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Thu Jul 18 20:50:09 2013 +0000
Committer: Cory Johns <cj...@slashdotmedia.com>
Committed: Mon Jul 22 14:31:07 2013 +0000

----------------------------------------------------------------------
 Allura/allura/ext/admin/admin_main.py           | 26 +++++++++-
 Allura/allura/lib/widgets/project_list.py       |  4 ++
 .../lib/widgets/resources/css/screenshots.css   | 21 ++++++++
 .../lib/widgets/resources/js/screenshots.js     | 10 ++++
 Allura/allura/model/project.py                  |  3 +-
 .../templates/widgets/project_screenshots.html  | 50 ++++++++++++--------
 Allura/allura/tests/functional/test_admin.py    | 22 +++++++++
 7 files changed, 112 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/fca6878b/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 1083d86..f8c8983 100644
--- a/Allura/allura/ext/admin/admin_main.py
+++ b/Allura/allura/ext/admin/admin_main.py
@@ -449,14 +449,20 @@ class ProjectAdminController(BaseController):
     @validate(W.screenshot_admin)
     def add_screenshot(self, screenshot=None, caption=None, **kw):
         require_access(c.project, 'update')
-        if len(c.project.get_screenshots()) >= 6:
+        screenshots = c.project.get_screenshots()
+        if len(screenshots) >= 6:
             flash('You may not have more than 6 screenshots per project.','error')
         elif screenshot is not None and screenshot != '':
             M.AuditLog.log('add screenshot')
+            sort = 1 + max([ss.sort or 0 for ss in screenshots] or [0])
             M.ProjectFile.save_image(
                 screenshot.filename, screenshot.file, content_type=screenshot.type,
                 save_original=True,
-                original_meta=dict(project_id=c.project._id,category='screenshot',caption=caption),
+                original_meta=dict(
+                    project_id=c.project._id,
+                    category='screenshot',
+                    caption=caption,
+                    sort=sort),
                 square=True, thumbnail_size=(150,150),
                 thumbnail_meta=dict(project_id=c.project._id,category='screenshot_thumb'))
             g.post_event('project_updated')
@@ -464,6 +470,22 @@ class ProjectAdminController(BaseController):
 
     @expose()
     @require_post()
+    def sort_screenshots(self, **kw):
+        """Sort project screenshots.
+
+        Called via ajax when screenshots are reordered via drag/drop on
+        the Screenshots admin page.
+
+        ``kw`` is a mapping of (screenshot._id, sort_order) pairs.
+
+        """
+        for s in c.project.get_screenshots():
+            if str(s._id) in kw:
+                s.sort = int(kw[str(s._id)])
+        g.post_event('project_updated')
+
+    @expose()
+    @require_post()
     def delete_screenshot(self, id=None, **kw):
         require_access(c.project, 'update')
         if id is not None and id != '':

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/fca6878b/Allura/allura/lib/widgets/project_list.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/project_list.py b/Allura/allura/lib/widgets/project_list.py
index 6d6649d..a5a327f 100644
--- a/Allura/allura/lib/widgets/project_list.py
+++ b/Allura/allura/lib/widgets/project_list.py
@@ -163,3 +163,7 @@ class ProjectScreenshots(ew_core.Widget):
         ew_core.Widget.defaults,
         project=None,
         edit=False)
+
+    def resources(self):
+        yield ew.JSLink('js/screenshots.js')
+        yield ew.CSSLink('css/screenshots.css')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/fca6878b/Allura/allura/lib/widgets/resources/css/screenshots.css
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/resources/css/screenshots.css b/Allura/allura/lib/widgets/resources/css/screenshots.css
new file mode 100644
index 0000000..08be2aa
--- /dev/null
+++ b/Allura/allura/lib/widgets/resources/css/screenshots.css
@@ -0,0 +1,21 @@
+.sortable {
+    float: left;
+}
+.sortable .screenshot {
+    margin: 0 0 10px 10px;
+    border: 1px solid #eee;
+    background: #fff;
+    float: left;
+}
+.sortable .screenshot .image {
+    margin-left: 0;
+    float: left;
+}
+.sortable .screenshot .image img {
+    display: block;
+}
+.sortable .screenshot .controls {
+    margin: 50px 15px 0 20px;
+    width: 190px;
+    float: left;
+}

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/fca6878b/Allura/allura/lib/widgets/resources/js/screenshots.js
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/resources/js/screenshots.js b/Allura/allura/lib/widgets/resources/js/screenshots.js
new file mode 100644
index 0000000..032a17c
--- /dev/null
+++ b/Allura/allura/lib/widgets/resources/js/screenshots.js
@@ -0,0 +1,10 @@
+$(function() {
+  $('.sortable').sortable({cursor: 'move'}).bind('sortupdate', function(e) {
+    var params = {'_session_id': $.cookie('_session_id')};
+    $(this).find('.screenshot').each(function(i) {
+      params[$(this).data('ss-id')] = i;
+    });
+    $.post('sort_screenshots', params);
+  });
+});
+

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/fca6878b/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index b889515..435cbbb 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -57,6 +57,7 @@ class ProjectFile(File):
     project_id=FieldProperty(S.ObjectId)
     category=FieldProperty(str)
     caption=FieldProperty(str)
+    sort=FieldProperty(int)
 
 class ProjectCategory(MappedClass):
     class __mongometa__:
@@ -287,7 +288,7 @@ class Project(MappedClass, ActivityNode, ActivityObject):
     def get_screenshots(self):
         return ProjectFile.query.find(dict(
                 project_id=self._id,
-                category='screenshot')).all()
+                category='screenshot')).sort('sort').all()
 
     @LazyProperty
     def icon(self):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/fca6878b/Allura/allura/templates/widgets/project_screenshots.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/widgets/project_screenshots.html b/Allura/allura/templates/widgets/project_screenshots.html
index 14c2d6f..01d9849 100644
--- a/Allura/allura/templates/widgets/project_screenshots.html
+++ b/Allura/allura/templates/widgets/project_screenshots.html
@@ -16,26 +16,34 @@
        specific language governing permissions and limitations
        under the License.
 -#}
-{% for ss in project.get_screenshots() %}
-  <div class="grid-6" style="text-align: center">
-    <a href="{{project.url()}}screenshot/{{ss.filename}}"><img src="{{project.url()}}screenshot/{{ss.filename}}/thumb" alt="Screenshot thumbnail"/></a>
-    {% if not edit %}
-    <br>
-    {{ss.caption}}
+{% set screenshots = project.get_screenshots() %}
+{% if screenshots.__len__() > 1 %}
+<p>Drag screenshots to sort.</p>
+{% endif %}
+<div class="sortable">
+  {% for ss in screenshots %}
+  <div data-ss-id="{{ ss._id }}" class="screenshot">
+    <div class="image">
+      <a href="{{project.url()}}screenshot/{{ss.filename}}"><img src="{{project.url()}}screenshot/{{ss.filename}}/thumb" alt="Screenshot thumbnail"/></a>
+      {% if not edit %}
+      <br>
+      {{ss.caption}}
+      {% endif %}
+    </div>
+    {% if edit %}
+    <div class="controls">
+      <form action="edit_screenshot" method="post">
+        <input type="hidden" value="{{ss._id}}" name="id">
+        <input type="text" value="{{ss.caption}}" name="caption"><br>
+        <input type="submit" value="Save Changes">
+      </form>
+      <form action="delete_screenshot" method="post">
+        <input type="hidden" value="{{ss._id}}" name="id">
+        <input type="submit" value="Delete">
+      </form>
+    </div>
     {% endif %}
   </div>
-  {% if edit %}
-  <div class="grid-12" style="margin-top:50px; min-height: 110px">
-    <form action="edit_screenshot" method="post">
-      <input type="hidden" value="{{ss._id}}" name="id">
-      <input type="text" value="{{ss.caption}}" name="caption"><br>
-      <input type="submit" value="Save Changes">
-    </form>
-    <form action="delete_screenshot" method="post">
-      <input type="hidden" value="{{ss._id}}" name="id">
-      <input type="submit" value="Delete">
-    </form>
-  </div>
-  {% endif %}
-{% endfor %}
-<div style="clear:both">&nbsp;</div>
\ No newline at end of file
+  {% endfor %}
+</div>
+<div style="clear:both">&nbsp;</div>

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/fca6878b/Allura/allura/tests/functional/test_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_admin.py b/Allura/allura/tests/functional/test_admin.py
index 8b1d703..7d630c9 100644
--- a/Allura/allura/tests/functional/test_admin.py
+++ b/Allura/allura/tests/functional/test_admin.py
@@ -263,6 +263,28 @@ class TestProjectAdmin(TestController):
         #r = self.app.get('/p/test/home/')
         #assert 'aaa' not in r
 
+    def test_sort_screenshots(self):
+        for file_name in ('admin_24.png', 'admin_32.png'):
+            file_path = os.path.join(allura.__path__[0], 'nf', 'allura',
+                    'images', file_name)
+            file_data = file(file_path).read()
+            upload = ('screenshot', file_name, file_data)
+            self.app.post('/admin/add_screenshot', params=dict(
+                    caption=file_name),
+                    upload_files=[upload])
+
+        p_nbhd = M.Neighborhood.query.get(name='Projects')
+        project = M.Project.query.get(shortname='test',
+                neighborhood_id=p_nbhd._id)
+        # first uploaded is first by default
+        screenshots = project.get_screenshots()
+        assert_equals(screenshots[0].filename, 'admin_24.png')
+        # reverse order
+        params = dict((str(ss._id), len(screenshots) - 1 - i)
+                for i, ss in enumerate(screenshots))
+        self.app.post('/admin/sort_screenshots', params)
+        assert_equals(project.get_screenshots()[0].filename, 'admin_32.png')
+
     def test_project_delete_undelete(self):
         # create a subproject
         with audits('create subproject sub-del-undel'):