Skip to content

Commit

Permalink
Add a GeoGit contrib package.
Browse files Browse the repository at this point in the history
  • Loading branch information
garnertb committed Jul 11, 2014
1 parent de2fa9e commit 6d5af74
Show file tree
Hide file tree
Showing 15 changed files with 332 additions and 5 deletions.
4 changes: 4 additions & 0 deletions geonode/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,10 @@ def metadata(self):
def original(self):
return self.get_query_set().filter(link_type='original')

def geogit(self):
return self.get_queryset().filter(name__icontains='geogit')


class Link(models.Model):
"""Auxiliary model for storing links for resources.
Expand Down
1 change: 1 addition & 0 deletions geonode/contrib/geogit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

49 changes: 49 additions & 0 deletions geonode/contrib/geogit/static/geogit/css/geogit.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#copy-button {
cursor: pointer;
}

#clone-url {
cursor: text;
}

.table-center {
display: table-cell;
vertical-align: middle;
text-align: center;
}

.stat-title {
color: #999;
font-size: 14px;
font-variant: small-caps;
}

.stat-value {
font-size: 21px;
}

.commit {
padding: 5px;
margin-left: 20px;
}

.commit-id {
color: #999;
}

.commit-message {
margin-bottom: 4px;
border-bottom: solid 1px #efefef;
}
.commit-author {
font-weight: bold;
color: #999;
}

.commit-timestamp {
color: #999;
}

#copy-button.fa {
display: table-cell;
}
86 changes: 86 additions & 0 deletions geonode/contrib/geogit/static/geogit/geogit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
'use strict';

(function() {

var module = angular.module('geogit', []);
var http, rootScope;
var service_ = null;
var q = null;


module.service('geoGitService', function($q, $http) {
return {
geogitCommand: function(url) {
var deferred = new $q.defer();
if (url) {
var request = url + '&callback=JSON_CALLBACK';
$http.jsonp(request).success(function(data, status) {
deferred.resolve(data);
}).error(function(error) {
deferred.reject(error);
});
return deferred.promise;
}
}
};
});

/*
* Main search controller
* Load data from api and defines the multiple and single choice handlers
* Syncs the browser url with the selections
*/
module.controller('geogitController', function($scope, geogitConfig, geoGitService) {
var errorText = 'There was an error receiving the latest GeoGit stats.';
$scope.geoserverURL = geogitConfig.geoserverURL;
$scope.workspace = geogitConfig.workspace;
$scope.typename = geogitConfig.typename;
$scope.store = geogitConfig.store;
$scope.statisticsURL = geogitConfig.statisticsURL;
$scope.logURL = geogitConfig.logURL;
$scope.repoURL = geogitConfig.repoURL;

if ($scope.statisticsURL) {
geoGitService.geogitCommand($scope.statisticsURL).then(
function(data) {
if (data.response.success) {
$scope.stats = data.response.Statistics;
$('#geogit-message').hide();
$('#geogit-stats').show();
}
},
function(error) {
$scope.error = error;
$('#geogit-message > h4').text(errorText);
console.log(error);
});
}

if ($scope.logURL) {
geoGitService.geogitCommand($scope.logURL).then(
function(data) {
if (data.response.success) {
$('#geogit-message').hide();
$('#geogit-stats').show();
var response = data.response.commit;
if (!Array.isArray(response)) {
$scope.commits = [response];
} else {
$scope.commits = response;
}
for (var i = 0; i < $scope.commits.length; i++) {
var commit = $scope.commits[i];
if (commit.author) {
commit.commitTimeSince = moment().calendar(commit.author.timestamp);
}
}
}
},
function(error) {
$scope.error = error;
$('#geogit-message > h4').text(errorText);
});
}

});
})();
55 changes: 55 additions & 0 deletions geonode/contrib/geogit/templates/_geogit_layer_detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{% load dialogos_tags %}
{% load bootstrap_tags %}
{% load i18n %}


{% verbatim %}
<div id="geogit" ng-controller="geogitController">
<div id="geogit-tab">
<div id="geogit-message">
<i class="fa fa-spinner fa-spin"></i>
<h4>Pulling latest GeoGit data.</h4>
</div>
<div id="geogit-stats" style="display: none">
<dt>Clone URL:</dt>
<div class="form-group">
<div class="input-group">
<i class="input-group-addon fa fa-clipboard" data-clipboard-text="{{ repoURL }}" id="copy-button" data-toggle="tooltip"
title="Copy the clone url."></i>
<input class="form-control" id="clone-url" type="email" value="{{ repoURL }}" readonly>
</div>
</div>
<dt>About this GeoGit Layer:</dt>
<table class="table table-bordered">
<tr>
<td class="table-center">
<div class="stat-title">total commits</div>
<div class="stat-value">{{ stats.totalCommits | number}}</div>

</td>
<td class="table-center">
<div class="stat-title">total contributors</div>
<div class="stat-value">{{ stats.Authors.totalAuthors || 0 | number}}</div>
</td>
</tr>
</table>
<dt>Recent Commit History:</dt>

<div ng-repeat-start="commit in commits">
<div class="commit" id="commit-{{ commit.id }}">
<span class="label label-primary pull-right">{{ commit.id | limitTo: 10 }}</span>
<h4 class="commit-message">{{ commit.message }}</h4>
<span class="commit-timestamp">Authored <span class="gray">{{ commit.commitTimeSince }}</span> by: </span>
<span class="commit-author">{{ commit.author.name || 'Unknown' }}</span>

</div>



</div>
<span ng-repeat-end></span>
</div>
</div>

</div>
{% endverbatim %}
45 changes: 45 additions & 0 deletions geonode/contrib/geogit/templates/_geogit_scripts.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{% load geogit_tags %}

{% if DEBUG_STATIC %}
<script src="{{ STATIC_URL }}lib/js/jquery.min.js"></script>
<script src="{{ STATIC_URL }}lib/js/angular.js"></script>
<script src="{{ STATIC_URL }}lib/js/bootstrap.min.js"></script>
<script src="{{ STATIC_URL }}lib/js/ZeroClipboard.min.js"></script>
<script src="{{ STATIC_URL }}lib/js/moment.min.js"></script>
{% endif %}
<script src="{{ STATIC_URL }}geogit/geogit.js"></script>
<link href="{{ STATIC_URL }}geogit/css/geogit.css" rel="stylesheet"/>

<script type="text/javascript">
var module = angular.module('g', ['geogit']);
module.constant('geogitConfig', {
workspace: '{{ resource.workspace }}',
store: '{{ resource.store }}',
typename: '{{ resource.typename }}',
geoserverURL: '{{ GEOSERVER_BASE_URL }}',
statisticsURL: '{% geogit_statistics_url resource %}',
logURL: '{% geogit_log_url resource %}',
repoURL: '{% geogit_repo_url resource %}'
});
angular.bootstrap(document, ['g']);

ZeroClipboard.config( { swfPath: '/static/lib/img/ZeroClipboard.swf' } );
var client = new ZeroClipboard( document.getElementById("copy-button") );

client.on( 'ready', function( readyEvent ) {
client.on( 'aftercopy', function( event ) {
alert('Copied ' + event.data['text/plain'] + ' to the clipboard.');
} );
} );

moment.lang('en', {
calendar : {
lastDay : '[Yesterday at] LT',
sameDay : '[Today at] LT',
nextDay : '[Tomorrow at] LT',
lastWeek : '[last] dddd [at] LT',
nextWeek : 'dddd [at] LT',
sameElse : '[on] D MMM YYYY'
}
});
</script>
1 change: 1 addition & 0 deletions geonode/contrib/geogit/templatetags/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

15 changes: 15 additions & 0 deletions geonode/contrib/geogit/templatetags/geogit_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django import template

register = template.Library()

@register.simple_tag
def geogit_statistics_url(layer):
return getattr(layer.link_set.filter(name__icontains='geogit statistics').first(), 'url', None)

@register.simple_tag
def geogit_log_url(layer):
return getattr(layer.link_set.filter(name__icontains='geogit log').first(), 'url', None)

@register.simple_tag
def geogit_repo_url(layer):
return getattr(layer.link_set.filter(name__icontains='clone in geogit').first(), 'url', None)
41 changes: 41 additions & 0 deletions geonode/geoserver/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,47 @@ def geoserver_post_save(instance, sender, **kwargs):
link_type='data',
)
)
if gs_resource.store.type.lower() == 'geogit':
repo_url = '{url}geogit/{workspace}:{store}'.format(url=ogc_server_settings.public_url,
workspace=instance.workspace,
store=instance.store)

path = gs_resource.dom.findall('nativeName')

if path:
path = 'path={path}'.format(path=path[0].text)

Link.objects.get_or_create(resource=instance.resourcebase_ptr,
url=repo_url,
defaults=dict(extension='html',
name='Clone in GeoGit',
mime='text/xml',
link_type='html'
)
)

command_url = lambda command: "{repo_url}/{command}.json?{path}".format(repo_url=repo_url,
path=path,
command=command)

Link.objects.get_or_create(resource=instance.resourcebase_ptr,
url=command_url('log'),
defaults=dict(extension='json',
name='GeoGit log',
mime='application/json',
link_type='html'
)
)

Link.objects.get_or_create(resource=instance.resourcebase_ptr,
url=command_url('statistics'),
defaults=dict(extension='json',
name='GeoGit statistics',
mime='application/json',
link_type='html'
)
)


elif instance.storeType == 'coverageStore':
#FIXME(Ariel): This works for public layers, does it work for restricted too?
Expand Down
3 changes: 3 additions & 0 deletions geonode/layers/templates/layers/_actions.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
{% endif %}
<li><a href="#rate" data-toggle="tab"><i class="fa fa-star"></i>{% trans "Ratings" %}</a></li>
<li><a href="#comments" data-toggle="tab"><i class="fa fa-comment-o"></i> {% trans "Comments" %}</a></li>
{% if GEOGIT_ENABLED and resource.link_set.geogit %}
<li><a href="#geogit" data-toggle="tab"><i class="fa fa-code-fork"></i> {% trans "GeoGit" %}</a></li>
{% endif %}
</ul>
18 changes: 18 additions & 0 deletions geonode/layers/templates/layers/layer_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ <h4>{% trans "External service layer" %}</h4>
{% endwith %}
</article>

{% if GEOGIT_ENABLED and resource.link_set.geogit %}
{% with "_geogit_layer_detail.html" as geogit_template %}
<article id="geogit" class="tab-pane">
{% with resource as obj %}
{% include geogit_template %}
{% endwith %}
</article>
{% endwith %}
{% endif %}

<article id="rate" class="tab-pane">
<!-- TODO: Move this to a reusable template snippet -->
{% if request.user.is_authenticated %}
Expand Down Expand Up @@ -291,7 +301,15 @@ <h4>{% trans "Permissions" %}</h4>
{% include "_permissions_form.html" %}
{% endif %}
{% endblock %}

{% block extra_script %}

{% if GEOGIT_ENABLED and resource.link_set.geogit %}
{% with "_geogit_scripts.html" as geogit_scripts_template %}
{% include geogit_scripts_template %}
{% endwith %}
{% endif %}

{% if request.user.is_authenticated %}
{% user_rating_js request.user resource "layer" %}
{% else %}
Expand Down
4 changes: 3 additions & 1 deletion geonode/static/bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"jquery-ajaxprogress": "https://github.com/kpozin/jquery-ajaxprogress.git",
"jquery.ajaxQueue": "https://github.com/gnarf/jquery-ajaxQueue.git",
"angular": "1.2.6",
"angular-leaflet-directive": "~0.7.3"
"angular-leaflet-directive": "~0.7.3",
"zeroclipboard": "2.1.5",
"moment": "2.7.0"
}
}
Loading

0 comments on commit 6d5af74

Please sign in to comment.