Skip to content
This repository was archived by the owner on Dec 11, 2024. It is now read-only.

Commit a346ce6

Browse files
authored
Merge pull request #76 from Kirubamoh/main
2 parents 1585c0b + 85fe380 commit a346ce6

19 files changed

+714
-142
lines changed

fixtures/test_data.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
-- possibly need to convert to GeometryCollection from FeatureCollection if we face that in GeoJSON the wild: https://gis.stackexchange.com/questions/177254/create-a-geosgeometry-from-a-featurecollection-in-geodangoINSERT INTO public.publications_publication VALUES
33

44
INSERT INTO public.publications_publication VALUES
5-
(1, 'The First Article', 'This is the first article. It is good in Münster.', '2010-10-10 10:10:10', ST_GeomFromGeoJSON('
5+
(1, 'The First Article', 'This is the first article. It is good in Münster.', '2010-10-10 10:10:10',NULL, 'https://service.tib.eu/optimeta/index.php/optimeta/article/view/8' , ST_GeomFromGeoJSON('
66
{
77
"type": "GeometryCollection",
88
"geometries": [{
@@ -24,8 +24,8 @@ INSERT INTO public.publications_publication VALUES
2424
[7.599984296478425,51.984257653537384]
2525
]]
2626
}]
27-
}'), now(), now(), '10.5555/12345678', NULL),
28-
(2, 'Paper Two', 'A second article. It is better; from Hanover to Berlin.', '2011-11-11 11:11:11', ST_GeomFromGeoJSON('
27+
}'),'Journal of Optimal Geolocations', now(), now(), '{"2022-06-01"}','{"2022-06-08"}'),
28+
(2, 'Paper Two', 'A second article. It is better; from Hanover to Berlin.', '2011-11-11 11:11:11','10.5555/12345678', NULL , ST_GeomFromGeoJSON('
2929
{
3030
"type": "GeometryCollection",
3131
"geometries": [{
@@ -45,4 +45,4 @@ INSERT INTO public.publications_publication VALUES
4545
[13.396695482095708,52.517051586549286]
4646
]
4747
}]
48-
}'), now(), now(), NULL, 'http://paper.url/two')
48+
}'), 'Journal of Optimal Geolocations',now(), now(), '{"2022-02-01"}','{"2022-03-31"}')

publications/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
from rest_framework import routers
44

5-
from publications.viewsets import PublicationViewSet
5+
from publications.viewsets import PublicationViewSet,SubscriptionViewset
66

77
router = routers.DefaultRouter()
88
router.register(r"publications", PublicationViewSet)
9-
9+
router.register(r"subscriptions",SubscriptionViewset,basename='Subscription')
1010
urlpatterns = router.urls

publications/models.py

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,42 @@
1-
from django.db import models
2-
"""Markers models."""
3-
41
from django.contrib.gis.db import models
5-
from datetime import date
2+
from django.contrib.postgres.fields import ArrayField
63

74

85
class Publication(models.Model):
9-
"""A scientific publication with a title and location."""
10-
11-
title = models.CharField(max_length=4096)
12-
abstract = models.TextField()
13-
publicationDate = models.DateField()
6+
7+
title = models.CharField(max_length=4096,null =True)
8+
abstract = models.TextField(null=True)
9+
publicationDate = models.DateField(null=True)
1410
doi = models.CharField(max_length=1024, null=True)
1511
url = models.URLField(max_length=1024, null=True)
16-
geometry = models.GeometryCollectionField()
12+
geometry = models.GeometryCollectionField(verbose_name='Publication geometry (Points, Lines, Polygons as GeoJSON)',srid = 4326, null=True, blank=True)
1713
journal = models.CharField(max_length=1024, null=True)
18-
19-
creationDate = models.DateTimeField(auto_now_add=True)
20-
lastUpdate = models.DateTimeField(auto_now=True)
14+
creationDate = models.DateTimeField(auto_now_add=True,null=True)
15+
lastUpdate = models.DateTimeField(auto_now=True,null=True)
16+
timeperiod_startdate = ArrayField(models.DateField(null=True), null=True)
17+
timeperiod_enddate = ArrayField(models.DateField(null=True), null=True)
2118

2219
def __str__(self):
2320
"""Return string representation."""
2421
return self.title
22+
23+
class OJSservers(models.Model):
24+
25+
url_field = models.URLField(max_length = 200)
26+
harvest_interval_minutes = models.IntegerField(default=60*24*3)
27+
last_harvest = models.DateTimeField(auto_now_add=True,null=True)
28+
29+
class Subscription(models.Model):
30+
name = models.CharField(max_length=4096)
31+
timeperiod_startdate = models.DateField(null=True)
32+
timeperiod_enddate = models.DateField(null=True)
33+
search_area = models.GeometryCollectionField(null=True, blank=True)
34+
user_name = models.CharField(max_length=4096)
35+
36+
def __str__(self):
37+
"""Return string representation."""
38+
return self.name
39+
40+
class Meta:
41+
ordering = ['user_name']
42+
verbose_name = "subscription"

publications/serializers.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,24 @@
33
from rest_framework_gis import serializers
44
from .models import Publication
55

6-
from publications.models import Publication
7-
6+
from publications.models import Publication,Subscription
87

98
class PublicationSerializer(serializers.GeoFeatureModelSerializer):
109
"""publication GeoJSON serializer."""
1110

1211
class Meta:
1312
"""publication serializer meta class."""
1413
model = Publication
15-
#fields = ("id", "name" ,"date")
16-
fields = ("title" ,"abstract", "publicationDate", "url", "doi")
14+
fields = ("title" ,"abstract", "publicationDate", "url", "doi","creationDate", "lastUpdate","timeperiod_startdate","timeperiod_enddate")
1715
geo_field = "geometry"
1816
auto_bbox = True
1917

20-
21-
18+
class SubscriptionSerializer(serializers.GeoFeatureModelSerializer):
19+
"""Subscription GeoJSON serializer."""
20+
21+
class Meta:
22+
model = Subscription
23+
fields = ("search_text","timeperiod_startdate","timeperiod_enddate","user_name")
24+
geo_field = "search_area"
25+
auto_bbox = True
2226

publications/static/js/main.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ async function initMap() {
1919
//"Esri World Imagery": esriWorldImageryLayer
2020
};
2121

22-
publicationsGroup = new L.FeatureGroup();
22+
var publicationsGroup = new L.FeatureGroup();
2323
map.addLayer(publicationsGroup);
2424

2525
var overlayMaps = {
@@ -42,9 +42,22 @@ async function initMap() {
4242
}
4343

4444
function publicationPopup(feature, layer) {
45-
var popupContent = '<h3>'+ feature.properties['title']+'</h3>' +
46-
'<l>'+ feature.properties['abstract']+ '</l>'+'<br>'+
47-
'<a href="http://www.google.com">Visit Article</a>' ;
45+
var popupContent = '';
46+
if (feature.properties['title']) {
47+
popupContent += '<h3>'+ feature.properties['title']+'</h3>'
48+
}
49+
50+
if (feature.properties['timeperiod_startdate'] && feature.properties['timeperiod_enddate']) {
51+
popupContent += '<l>' + '<b>' + "Timeperiod : " + '</b>' + "&nbsp;"+ "from" + "&nbsp;"+ feature.properties['timeperiod_startdate'] + "&nbsp;" + "to" + "&nbsp;" + feature.properties['timeperiod_enddate'] +'</l>' +'<br>';
52+
}
53+
54+
if (feature.properties['abstract']) {
55+
popupContent += '<p>'+ feature.properties['abstract']+ '</p>'+'<br>'
56+
}
57+
58+
if (feature.properties['url']) {
59+
popupContent += '<a href=' + feature.properties['url']+ '>' + "Visit Article" + '</a>' ;
60+
}
4861

4962
if (feature.properties && feature.properties.popupContent) {
5063
popupContent += feature.properties.popupContent;
@@ -64,10 +77,5 @@ $(function () {
6477
initMap();
6578
});
6679

67-
// email sent alert
68-
$(document).ready(function(){
69-
$( 'button').click(function() {
70-
$('.alert').show()
71-
})
72-
});
80+
7381

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
//to trigger datepicker
2+
$(function () {
3+
$('#datepicker1').datepicker({
4+
clearBtn : true,
5+
});
6+
$('#datepicker2').datepicker({
7+
clearBtn : true,
8+
});
9+
});
10+
11+
async function getsubscription() {
12+
const subscription_url = '/api/subscriptions/'
13+
try {
14+
let res = await fetch(subscription_url);
15+
return await res.json();
16+
} catch (error) {
17+
console.log(error);
18+
}
19+
}
20+
21+
async function rendersubscriptions() {
22+
let data = await getsubscription();
23+
const f = data.features.length
24+
if (f >= 1) {
25+
for (var index = 0; index < f ; ++index){
26+
temp = document.getElementById("accordion1");
27+
let p = document.createElement("div")
28+
p.className = "card";
29+
temp.appendChild(p);
30+
let q = document.createElement("div");
31+
q.className = "card-header";
32+
q.id = "heading";
33+
count_heading = index+1 ;
34+
q.id += count_heading;
35+
p.appendChild(q);
36+
let btn = document.createElement("button");
37+
btn.className = "btn btn-link";
38+
btn.setAttribute("data-toggle","collapse");
39+
c = "collapse"
40+
count_collapse = index+1 ;
41+
c += count_collapse;
42+
btn.setAttribute("data-target","#"+c);
43+
btn.setAttribute("aria-expanded","false");
44+
btn.setAttribute("aria-controls",c);
45+
btn.innerHTML = data.features[index].properties['search_text'];
46+
q.appendChild(btn);
47+
let r = document.createElement("div");
48+
r.id = c;
49+
r.className = "collapse";
50+
r.setAttribute("aria-labelledby",q.id);
51+
r.setAttribute("data-parent","#accordion1");
52+
p.appendChild(r);
53+
let s = document.createElement("div");
54+
s.className = "card-body";
55+
s.innerHTML = 'timeperiod : ' + data.features[index].properties['timeperiod_startdate'] + "//" + data.features[index].properties['timeperiod_enddate'] ;
56+
r.appendChild(s);
57+
}
58+
} else {
59+
temp = document.getElementById("accordion1");
60+
temp.innerHTML += '<br>'+'<p class = "lead">'+ "You do not have any active subscriptions yet. Please click on Add New Subcription to add journals you want!" + '</p>'
61+
}
62+
}
63+
rendersubscriptions();
64+
65+
66+
//to trigger datepicker
67+
$(function () {
68+
$('#datepicker1').datepicker({
69+
clearBtn : true,
70+
});
71+
$('#datepicker2').datepicker({
72+
clearBtn : true,
73+
});
74+
});
75+
76+
async function getsubscription() {
77+
const subscription_url = '/api/subscriptions/'
78+
try {
79+
let res = await fetch(subscription_url);
80+
return await res.json();
81+
} catch (error) {
82+
console.log(error);
83+
}
84+
}
85+
86+
async function rendersubscriptions() {
87+
let data = await getsubscription();
88+
const f = data.features.length
89+
if (f >= 1) {
90+
for (var index = 0; index < f ; ++index){
91+
temp = document.getElementById("accordion1");
92+
let p = document.createElement("div")
93+
p.className = "card";
94+
temp.appendChild(p);
95+
let q = document.createElement("div");
96+
q.className = "card-header";
97+
q.id = "heading";
98+
count_heading = index+1 ;
99+
q.id += count_heading;
100+
p.appendChild(q);
101+
let btn = document.createElement("button");
102+
btn.className = "btn btn-link";
103+
btn.setAttribute("data-toggle","collapse");
104+
c = "collapse"
105+
count_collapse = index+1 ;
106+
c += count_collapse;
107+
btn.setAttribute("data-target","#"+c);
108+
btn.setAttribute("aria-expanded","false");
109+
btn.setAttribute("aria-controls",c);
110+
btn.innerHTML = data.features[index].properties['search_text'];
111+
q.appendChild(btn);
112+
let r = document.createElement("div");
113+
r.id = c;
114+
r.className = "collapse";
115+
r.setAttribute("aria-labelledby",q.id);
116+
r.setAttribute("data-parent","#accordion1");
117+
p.appendChild(r);
118+
let s = document.createElement("div");
119+
s.className = "card-body";
120+
s.innerHTML = 'timeperiod : ' + data.features[index].properties['timeperiod_startdate'] + "//" + data.features[index].properties['timeperiod_enddate'] ;
121+
r.appendChild(s);
122+
}
123+
} else {
124+
temp = document.getElementById("accordion1");
125+
temp.innerHTML += '<br>'+'<p class = "lead">'+ "You do not have any active subscriptions yet. Please click on Add New Subcription to add journals you want!" + '</p>'
126+
}
127+
}
128+
rendersubscriptions();
129+
130+
131+
132+
133+

publications/static/js/timeline.js

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,51 @@
1+
const container = document.getElementById("timeline");
2+
3+
// Create a DataSet (allows two way data-binding)
4+
const articles = new vis.DataSet([
5+
{ id: 1, content: "article 1", start: "2007-03-05", end: "2015-10-10" },
6+
{ id: 2, content: "article 2", start: "2005-08-23", end: "2013-06-01" },
7+
{ id: 3, content: "article 3", start: "2015-08-20", end: "2018-04-26"},
8+
{ id: 4, content: "article 4", start: "2004-01-11", end: "2005-02-25" },
9+
{ id: 5, content: "article 5", start: "2011-03-12", end: "2014-10-11"},
10+
{ id: 6, content: "article 6", start: "2002-02-25", end : "2013-02-25" , title : '<b>titleofarticle</b><br><p>Journal</p>'},
11+
{ id: 7, content: "article 7", start: "2003-08-04", end: "2012-07-08" },
12+
{ id: 8, content: "article 8", start: "2011-03-18", end: "2011-10-28" },
13+
{ id: 9, content: "article 9", start: "2011-06-04", end: "2014-09-29" },
14+
{ id: 10, content: "article 10", start: "2006-08-27", end: "2013-02-24" },
15+
{ id: 11, content: "article 11", start: "2002-01-28", end: "2004-10-19" },
16+
{ id: 12, content: "article 12", start: "2007-11-21", end: "2012-09-25" },
17+
{ id: 13, content: "article 13", start: "2005-01-20", end: "2011-04-20" },
18+
{ id: 14, content: "article 14", start: "2009-03-24", end: "2014-11-23" },
19+
{ id: 15, content: "article 15", start: "2002-10-16", end: "2008-02-20" },
20+
{ id: 16, content: "article 16", start: "2001-08-07", end: "2005-07-06" },
21+
{ id: 17, content: "article 17", start: "2006-12-24", end: "2015-11-04" },
22+
{ id: 18, content: "article 18", start: "2009-07-05", end: "2015-08-30" },
23+
{ id: 19, content: "article 19", start: "2014-06-02", end: "2015-05-20" },
24+
{ id: 20, content: "article 20", start: "2002-09-12", end: "2010-08-08" },
25+
{ id: 21, content: "article 21", start: "2008-03-04", end: "2013-05-04" },
26+
{ id: 22, content: "article 22", start: "2010-02-21", end: "2015-07-31" },
27+
{ id: 23, content: "article 23", start: "2004-10-30", end: "2006-04-07" },
28+
{ id: 24, content: "article 24", start: "2000-06-15", end: "2003-08-13" },
29+
{ id: 25, content: "article 25", start: "2011-03-19", end: "2014-10-29" },
30+
]);
31+
32+
// Configuration for the Timeline
33+
const options = {
34+
stack: true,
35+
verticalScroll: true,
36+
zoomKey: 'ctrlKey',
37+
maxHeight: 600,
38+
timeAxis: {scale: 'year', step: 2},
39+
start : "2000-01-01",
40+
};
41+
42+
// Create a Timeline
43+
timeline = new vis.Timeline(container, articles, options);
44+
//timeline.setWindow('2010-05-01', '2019-04-01');
45+
46+
47+
48+
149

2-
async function getarticle() {
3-
const publications_url = '/api/publications/'
4-
try {
5-
let res = await fetch(publications_url);
6-
return await res.json();
7-
} catch (error) {
8-
console.log(error);
9-
}
10-
}
11-
12-
async function renderarticle() {
13-
let data = await getarticle();
14-
console.log('Type:',data.features[0].properties['publicationDate'])
15-
const f = data.features.length
16-
for (var index = 0; index < f ; ++index){
17-
document.getElementById("timeline").innerHTML += '<li>' +'<a href="#">' + data.features[index].properties['title'] + "-" + data.features[index].properties['publicationDate'] +'</a>'+ '</li>';
18-
}
19-
}
20-
21-
renderarticle();
2250

2351

0 commit comments

Comments
 (0)