Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add account dashboard #169

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions django_project/base/static/css/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,7 @@ h6 {
color: #F05F40;
}
}

.bg-darken5 {
background-color: rgba(31, 51, 73, 0.05) !important;
}
16 changes: 10 additions & 6 deletions django_project/base/static/js/map_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ window.addEventListener("map:init", function (e) {
let lon = coord.lng;
if (currentTab.length != 0) {
let key = document.getElementById(currentTab + "-select").value;
fetch(currentTab, key, lat, lon, outputText);
let token = document.getElementById(currentTab + "-token").value;
fetch(currentTab, key, lat, lon, token);
}
});

Expand All @@ -25,6 +26,7 @@ window.addEventListener("map:init", function (e) {
let timer = '<div id="' + registry + '-timer"></div>';
let lat= '<label>Latitude: </label><input class=input-field type="number" step=0.0001 id="' + registry + '-lat-box" value="0.0000"/>';
let lng = '<label>Longitude: </label><input class=input-field type="number" step=0.0001 id="' + registry + '-lon-box" value="0.0000"/>';
let token = '<label>Token: </label><input class=input-field type="text" id="' + registry + '-token" value=""/>';
let button = '<button class="fetch-button" type="button" id=' + registry + '-button>Fetch</button>';
let options = '<label> '+ registry.charAt(0).toUpperCase() + registry.slice(1) + 's: </label><select class="select-dropdown" name="' + registry + '" id="' + registry + '-select">';
registries[registry].forEach(function (value) {
Expand All @@ -39,7 +41,7 @@ window.addEventListener("map:init", function (e) {
let output = '<div class="output" id="' + registry + '-output" style="display: none">' +
'<button class="output-text" disabled id="' + registry + '-text">Text</button>' +
'<button class="output-chart" id="' + registry + '-chart">Chart</button></div>';
html[registry] = lat + lng + button + options + output + timer + table + url;
html[registry] = lat + lng + token + button + options + output + timer + table + url;
};
// create the sidebar instance and add it to the map
L.control.sidebar({ container: 'sidebar' })
Expand Down Expand Up @@ -81,16 +83,18 @@ document.addEventListener('click',function(e) {
var lat = document.getElementById(currentTab + "-lat-box").value;
var lon = document.getElementById(currentTab + "-lon-box").value;
var key = document.getElementById(currentTab + "-select").value;
var token = document.getElementById(currentTab + "-token").value;
outputText = true;
fetch(currentTab, key, lat, lon);
fetch(currentTab, key, lat, lon, token);
}
if (e.target && e.target.id== currentTab + "-chart") {
var lat = document.getElementById(currentTab + "-lat-box").value;
var lon = document.getElementById(currentTab + "-lon-box").value;
var key = document.getElementById(currentTab + "-select").value;
var token = document.getElementById(currentTab + "-token").value;
outputText = false;
document.getElementById(currentTab + "-text").disabled = false;
fetch(currentTab, key, lat, lon);
fetch(currentTab, key, lat, lon, token);
}

}
Expand All @@ -99,14 +103,14 @@ document.addEventListener('click',function(e) {


// Functions
function fetch (registry, key, lat, lon){
function fetch (registry, key, lat, lon, token){
// We update all coord boxes on all tabs
updateCoordBoxes(lat, lon);
// We remove existing markers
if (marker) {marker.remove()};
marker = L.marker([lat, lon]).addTo(window.map);
let baseUrl = window.location.origin;
let url = encodeURI(baseUrl + '/api/v2/query?registry='+registry+'&key='+key+'&x='+lon+'&y='+lat+'&outformat=json');
let url = encodeURI(baseUrl + '/api/v2/query?registry='+registry+'&key='+key+'&x='+lon+'&y='+lat+'&token='+token+'&outformat=json');
let urlEl = document.getElementById(currentTab + "-url");
urlEl.innerHTML = '<h5>Geocontext API query</h5>' + url;
document.getElementById(currentTab + "-table").innerHTML = '<div class="loader"></div>'
Expand Down
4 changes: 4 additions & 0 deletions django_project/base/templates/main_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@
id="dropdown01" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">{{ user.username }}</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdown01">
{% if user.is_authenticated %}
<a class="dropdown-item" href="{% url 'profile' user.username %}">Profile</a>
{% endif %}

{% if user.is_staff or user.is_superuser %}
<a class="dropdown-item" href="/admin/">Admin Page</a>
<div class="dropdown-divider"></div>
Expand Down
Empty file added django_project/cache.py
Empty file.
5 changes: 4 additions & 1 deletion django_project/core/settings/dev_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
LOGGING_OUTPUT_ENABLED = DEBUG
LOGGING_LOG_SQL = DEBUG


DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
Expand All @@ -20,6 +21,8 @@
'PASSWORD': 'docker',
'HOST': 'db',
'PORT': 5432,
'TEST_NAME': 'unittests',
'TEST': {
'NAME': 'unittests'
},
}
}
2 changes: 1 addition & 1 deletion django_project/core/settings/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@
]

ENABLE_API_TOKEN = ast.literal_eval(
os.environ.get('ENABLE_API_TOKEN', 'False')
os.environ.get('ENABLE_API_TOKEN', 'True')
)
18 changes: 18 additions & 0 deletions django_project/geocontext/migrations/0004_auto_20220214_1440.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.1.14 on 2022-02-14 12:40

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('geocontext', '0003_userprofile_usertier'),
]

operations = [
migrations.AlterField(
model_name='usertier',
name='request_limit',
field=models.CharField(default='100/day', help_text='API request limit for user. Enter "-" for unlimited requests', max_length=100),
),
]
113 changes: 113 additions & 0 deletions django_project/geocontext/templates/geocontext/plan.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
{% extends 'main_base.html' %}
{% load static %}

{% block body_content %}
<div class="container">
<div id="layoutSidenav_content">
<main>
<!-- Pricing section-->
<section class="bg-light py-5 border-bottom">
<div class="container px-5 my-5">
<div class="text-center mb-5">
<h2 class="fw-bolder">Pricing plans</h2>
</div>
<div class="row gx-5 justify-content-center">
<!-- Pricing card free-->
<div class="col-lg-6 col-xl-4">
<div class="card mb-5 mb-xl-0">
<div class="card-body p-5">
<div class="small text-uppercase fw-bold text-muted">Open Tier</div>
<div class="mb-3">
<span class="display-4 fw-bold">$0</span>
<span class="text-muted">/ mo.</span>
</div>
<ul class="list-unstyled mb-4">
<li class="mb-2">
<i class="fa fa-check text-primary"></i>
<strong>1000 Requester per month</strong>
</li>
<li class="mb-2">
<i class="fa fa-remove text-muted"></i>
User Support
</li>
<li class="mb-2">
<i class="fa fa-remove text-muted"></i>
Define your own services
</li>
</ul>
<div class="d-grid"><a class="btn btn-outline-primary" onclick="choosePlan(1)" href="#!">Choose plan</a></div>
</div>
</div>
</div>
<!-- Pricing card pro-->
<div class="col-lg-6 col-xl-4">
<div class="card mb-5 mb-xl-0">
<div class="card-body p-5">
<div class="small text-uppercase fw-bold">
<i class="fa fa-star-fill text-warning"></i>
Small Tier
</div>
<div class="mb-3">
<span class="display-4 fw-bold">$100</span>
<span class="text-muted">/ mo.</span>
</div>
<ul class="list-unstyled mb-4">
<li class="mb-2">
<i class="fa fa-check text-primary"></i>
<strong>10000 Requester per month</strong>
</li>
<li class="mb-2">
<i class="fa fa-check text-primary"></i>
<strong>User Support</strong>
</li>
<li class="mb-2">
<i class="fa fa-remove text-muted"></i>
Define your own services
</li>
</ul>
<div class="d-grid"><a class="btn btn-primary" onclick="choosePlan(2)" href="#!">Choose plan</a></div>
</div>
</div>
</div>
<!-- Pricing card enterprise-->
<div class="col-lg-6 col-xl-4">
<div class="card">
<div class="card-body p-5">
<div class="small text-uppercase fw-bold text-muted">Medium</div>
<div class="mb-3">
<span class="display-4 fw-bold">$500</span>
<span class="text-muted">/ mo.</span>
</div>
<ul class="list-unstyled mb-4">
<li class="mb-2">
<i class="fa fa-check text-primary"></i>
<strong>100000 Requester per month</strong>
</li>
<li class="mb-2">
<i class="fa fa-check text-primary"></i>
<strong>User Support</strong>
</li>
<li class="mb-2">
<i class="fa fa-check text-primary"></i>
<strong>Define your own services</strong>
</li>
</ul>
<div class="d-grid"><a class="btn btn-outline-primary" onclick="choosePlan(3)" href="#!">Choose plan</a></div>
</div>
</div>
</div>
</div>
</div>
</section>
</main>
</div>
</div>
<script>
function choosePlan(tierId){
const url = `/geocontext/change-plan/?user_tier=${tierId}`
let request = new XMLHttpRequest();
request.open("GET", url)
request.send();
}
</script>
{% endblock %}
76 changes: 76 additions & 0 deletions django_project/geocontext/templates/user/profile.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{% extends 'main_base.html' %}
{% block title %}
{{ object.username }}
{% endblock %}

{% block body_content %}
<div class="container">
<div id="layoutSidenav_content">
<main>
<header class="page-header page-header-compact page-header-light border-bottom bg-white mb-4">
<div class="container-xl px-4">
<div class="page-header-content">
<div class="row align-items-center justify-content-between pt-3">
<div class="col-auto mb-3">
<h1 class="page-header-title">
<div class="page-header-icon"><i data-feather="user"></i></div>
Account Settings
</h1>
</div>
</div>
</div>
</div>
</header>
<!-- Main page content-->
<div class="container-xl px-4 mt-4">
<div class="row">
<div class="col-xl-4">
<!-- Profile picture card-->
<div class="mb-4 mb-xl-0">
<div class="mb-4">
<h4 class="fw-bolder">Account</h4>
<div class="text-muted">{{ object.username }}</div>
</div>
<div class="mb-4">
<h4 class="fw-bolder">Plan</h4>
<div class="text-muted">{{ plan.name }}
<a href="{% url 'plans' %}" class="pull-right btn btn-sm btn-primary-soft">Upgrade</a>
</div>
</div>
<div class="mb-4">
<a href="{% url 'plans' %}">View pricing plans</a>
</div>
</div>
</div>
<div class="col-xl-8">
<!-- Account details card-->
<div class="card card-waves mb-4 mt-5">
<div class="card-body p-5">
<div class="row align-items-center justify-content-between">
<div class="col">
<h2 class="text-primary" style="color: #007bff !important">Access Token</h2>
<p class="text-gray-700">You need an API access token.</p>
<a class="btn btn-primary" href="#!">
Generate new token
<i class="ms-1" data-feather="arrow-right"></i>
</a>
</div>

</div>
<hr>
<div class="col">
<h5>Your Token</h5>
<div class="relative clearfix bg-darken5 round" style="background-color: rgba(31, 51, 73, 0.05) !important; height: 50px; padding: 15px">
<code class="copy">{{ token }} <a href="#" id="copy"><i class="fa fa-clipboard pull-right" aria-hidden="true"></i></a></code>
</div>
</div>

</div>
</div>
</div>
</div>
</div>
</main>
</div>
</div>
{% endblock %}
21 changes: 19 additions & 2 deletions django_project/geocontext/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from django.conf.urls import url
from rest_framework.urlpatterns import format_suffix_patterns
from django.contrib.auth.decorators import login_required
from django.views.generic import RedirectView
from django.urls import reverse_lazy

from geocontext.views.api_v1 import (
CacheListAPI,
Expand All @@ -10,12 +13,13 @@
ServiceListAPIView,
RiverNameAPIView,
)
from geocontext.views.api_v2 import GenericAPIView
from geocontext.views.api_v2 import GenericAPIView, RegistryAPIView
from geocontext.views.collection import CollectionListView, CollectionDetailView
from geocontext.views.profile import ProfileView
from geocontext.views.plan import PlanListView, UpdatePlanApiView
from geocontext.views.service import ServiceListView, ServiceDetailView
from geocontext.views.group import GroupListView, GroupDetailView


urlpatterns = [
url(regex=r'^geocontext/$',
view=get_service,
Expand All @@ -38,6 +42,15 @@
url(regex=r'^geocontext/collection/(?P<slug>[\w-]+)/$',
view=CollectionDetailView.as_view(),
name='collection-detail'),
url(regex=r'^profile/(?P<slug>[\w-]+)/$',
view=ProfileView.as_view(),
name='profile'),
url(regex=r'^geocontext/plans/$',
view=PlanListView.as_view(),
name='plans'),
url(regex=r'^geocontext/change-plan/$',
view=UpdatePlanApiView.as_view(),
name='update-plan'),
]

urlpatterns_api_v1 = [
Expand Down Expand Up @@ -84,6 +97,10 @@
view=GenericAPIView.as_view(),
name='service-api'
),
url(regex=r'^registries$',
view=RegistryAPIView.as_view(),
name='registries-api'
)
]

urlpatterns_api_v2 = format_suffix_patterns(urlpatterns_api_v2)
Loading