From 99874b1323b21f8fce62314fa7214be86aad6a92 Mon Sep 17 00:00:00 2001 From: Nikolai R Kristiansen Date: Mon, 10 Nov 2014 22:40:11 +0100 Subject: [PATCH] Looks better --- mailadmin/static/app/scripts/main.js | 63 ++++---- mailadmin/static/app/styles/main.scss | 46 +++++- mailadmin/static/app/templates/list.html | 2 +- mailadmin/static/app/templates/orgunits.html | 3 + mailadmin/static/dist/scripts/main.js | 63 ++++---- mailadmin/static/dist/scripts/templates.js | 154 +++++++++++++++++++ mailadmin/static/dist/styles/main.css | 47 ++++++ mailadmin/static/dist/templates/list.js | 4 +- mailadmin/static/gulpfile.js | 6 +- mailadmin/static/package.json | 1 + mailadmin/templates/base.html | 10 +- mailadmin/templates/home.html | 37 +++-- mailadmin/templates/login_form.html | 9 ++ mailadmin/templates/nav.html | 24 +++ mailadmin/urls.py | 5 +- mailadmin/views.py | 11 +- mailadminsite/urls.py | 4 +- 17 files changed, 407 insertions(+), 82 deletions(-) create mode 100644 mailadmin/static/app/templates/orgunits.html create mode 100644 mailadmin/static/dist/scripts/templates.js create mode 100644 mailadmin/templates/login_form.html create mode 100644 mailadmin/templates/nav.html diff --git a/mailadmin/static/app/scripts/main.js b/mailadmin/static/app/scripts/main.js index 13b039b..a7f4355 100644 --- a/mailadmin/static/app/scripts/main.js +++ b/mailadmin/static/app/scripts/main.js @@ -1,32 +1,41 @@ $(document).ready(function() { - var api_urls = { - fwd_list: '/api/forwards/', - fwd_delete: '/api/forward/', - fwd_create: '/api/forward/', - ou_list: '/api/orgunits/', - }; - $.getJSON(api_urls.fwd_list, function(data) { - if( !data.cpanelresult ) { - $(".forwards-container").html("No results."); - return; - } + nunjucks.configure({ autoescape: true }); + var api_urls = { + fwd_list: '/api/forwards/', + fwd_delete: '/api/forward/', + fwd_create: '/api/forward/', + ou_list: '/api/orgunits/', + me: '/api/me/', + }; + if( $('body.home').length ) { + $.getJSON(api_urls.ou_list, function(data) { + var ou_html = nunjucks.render('orgunits.html', { + orgunits: data, + api_urls: api_urls + }); - var forwards = data.cpanelresult.data; - console.log(forwards); - var lists =_.groupBy(forwards, function(fwd) { return fwd.dest; }); - console.log(lists); - nunjucks.configure({ autoescape: true }); - var forward_html = nunjucks.render( - 'static/app/templates/list.html', - { - lists: lists, - api_urls: api_urls - }); + $(".orgunit-list").append(ou_html); + }); + + $.getJSON(api_urls.fwd_list, function(data) { + if( !data.cpanelresult ) { + $(".forwards-container").html("No results."); + return; + } - $(".forwards-container").html(forward_html); + var forwards = data.cpanelresult.data; + var lists =_.groupBy(forwards, function(fwd) { return fwd.dest; }); - $("input[name=fwd-delete]").click(function() { - $(this).parent().parent().toggleClass('danger'); - }); - }); + var fw_html = nunjucks.render('list.html', { + lists: lists, + api_urls: api_urls + }); + + $(".forwards-container").html(fw_html); + + $("input[name=fwd-delete]").click(function() { + $(this).parent().parent().toggleClass('danger'); + }); + }); + } }); \ No newline at end of file diff --git a/mailadmin/static/app/styles/main.scss b/mailadmin/static/app/styles/main.scss index b1995e7..704cefe 100644 --- a/mailadmin/static/app/styles/main.scss +++ b/mailadmin/static/app/styles/main.scss @@ -1 +1,45 @@ -@import "../../bower_components/bootstrap-sass-official/vendor/assets/stylesheets/bootstrap"; \ No newline at end of file +@import "../../bower_components/bootstrap-sass-official/vendor/assets/stylesheets/bootstrap"; + +.login-form { + margin: 0 auto; + max-width: 400px; + float: none; + input[type=submit] { + float: right; + } +} + +/* Hide for mobile, show later */ +.sidebar { + display: none; + @media (min-width: 768px) { + display: block; + } +} + +/* Sidebar navigation */ +.nav-sidebar > .active > a, +.nav-sidebar > .active > a:hover, +.nav-sidebar > .active > a:focus { + color: #fff; + background-color: #428bca; +} + +/* Sticky footer styles */ +html { + position: relative; + min-height: 100%; +} +body { + /* Margin bottom by footer height */ + margin-bottom: 60px; +} +.footer { + position: absolute; + bottom: 0; + width: 100%; + /* Set the fixed height of the footer here */ + height: 60px; + background-color: #f5f5f5; + padding-top: 20px; +} \ No newline at end of file diff --git a/mailadmin/static/app/templates/list.html b/mailadmin/static/app/templates/list.html index b1df4dc..a5d15f5 100644 --- a/mailadmin/static/app/templates/list.html +++ b/mailadmin/static/app/templates/list.html @@ -1,5 +1,5 @@ {% for list,members in lists %} -
+
{{ list }} {{members|length}}
diff --git a/mailadmin/static/app/templates/orgunits.html b/mailadmin/static/app/templates/orgunits.html new file mode 100644 index 0000000..72734c0 --- /dev/null +++ b/mailadmin/static/app/templates/orgunits.html @@ -0,0 +1,3 @@ +{% for ou in orgunits %} +
  • {{ ou.name }}
  • +{% endfor %} \ No newline at end of file diff --git a/mailadmin/static/dist/scripts/main.js b/mailadmin/static/dist/scripts/main.js index 13b039b..a7f4355 100644 --- a/mailadmin/static/dist/scripts/main.js +++ b/mailadmin/static/dist/scripts/main.js @@ -1,32 +1,41 @@ $(document).ready(function() { - var api_urls = { - fwd_list: '/api/forwards/', - fwd_delete: '/api/forward/', - fwd_create: '/api/forward/', - ou_list: '/api/orgunits/', - }; - $.getJSON(api_urls.fwd_list, function(data) { - if( !data.cpanelresult ) { - $(".forwards-container").html("No results."); - return; - } + nunjucks.configure({ autoescape: true }); + var api_urls = { + fwd_list: '/api/forwards/', + fwd_delete: '/api/forward/', + fwd_create: '/api/forward/', + ou_list: '/api/orgunits/', + me: '/api/me/', + }; + if( $('body.home').length ) { + $.getJSON(api_urls.ou_list, function(data) { + var ou_html = nunjucks.render('orgunits.html', { + orgunits: data, + api_urls: api_urls + }); - var forwards = data.cpanelresult.data; - console.log(forwards); - var lists =_.groupBy(forwards, function(fwd) { return fwd.dest; }); - console.log(lists); - nunjucks.configure({ autoescape: true }); - var forward_html = nunjucks.render( - 'static/app/templates/list.html', - { - lists: lists, - api_urls: api_urls - }); + $(".orgunit-list").append(ou_html); + }); + + $.getJSON(api_urls.fwd_list, function(data) { + if( !data.cpanelresult ) { + $(".forwards-container").html("No results."); + return; + } - $(".forwards-container").html(forward_html); + var forwards = data.cpanelresult.data; + var lists =_.groupBy(forwards, function(fwd) { return fwd.dest; }); - $("input[name=fwd-delete]").click(function() { - $(this).parent().parent().toggleClass('danger'); - }); - }); + var fw_html = nunjucks.render('list.html', { + lists: lists, + api_urls: api_urls + }); + + $(".forwards-container").html(fw_html); + + $("input[name=fwd-delete]").click(function() { + $(this).parent().parent().toggleClass('danger'); + }); + }); + } }); \ No newline at end of file diff --git a/mailadmin/static/dist/scripts/templates.js b/mailadmin/static/dist/scripts/templates.js new file mode 100644 index 0000000..fefaecc --- /dev/null +++ b/mailadmin/static/dist/scripts/templates.js @@ -0,0 +1,154 @@ +(function() {(window.nunjucksPrecompiled = window.nunjucksPrecompiled || {})["list.html"] = (function() {function root(env, context, frame, runtime, cb) { +var lineno = null; +var colno = null; +var output = ""; +try { +frame = frame.push(); +var t_3 = runtime.contextOrFrameLookup(context, frame, "lists"); +if(t_3) {var t_1; +if(runtime.isArray(t_3)) { +var t_2 = t_3.length; +for(t_1=0; t_1 < t_3.length; t_1++) { +var t_4 = t_3[t_1][0] +frame.set("list", t_3[t_1][0]); +var t_5 = t_3[t_1][1] +frame.set("members", t_3[t_1][1]); +frame.set("loop.index", t_1 + 1); +frame.set("loop.index0", t_1); +frame.set("loop.revindex", t_2 - t_1); +frame.set("loop.revindex0", t_2 - t_1 - 1); +frame.set("loop.first", t_1 === 0); +frame.set("loop.last", t_1 === t_2 - 1); +frame.set("loop.length", t_2); +output += "\n
    \n\t
    \n\t
    "; +output += runtime.suppressValue(t_4, env.autoesc); +output += " "; +output += runtime.suppressValue(env.getFilter("length").call(context, t_5), env.autoesc); +output += "
    \n\t\t
    \n\t\t\t\n\t\t \n\t\t\t \n\t\t\t \n\t\t \n\t \n\t \n\t\t\t"; +frame = frame.push(); +var t_8 = t_5; +if(t_8) {var t_7 = t_8.length; +for(var t_6=0; t_6 < t_8.length; t_6++) { +var t_9 = t_8[t_6]; +frame.set("member", t_9); +frame.set("loop.index", t_6 + 1); +frame.set("loop.index0", t_6); +frame.set("loop.revindex", t_7 - t_6); +frame.set("loop.revindex0", t_7 - t_6 - 1); +frame.set("loop.first", t_6 === 0); +frame.set("loop.last", t_6 === t_7 - 1); +frame.set("loop.length", t_7); +output += "\n\t\t\t\t\n\t\t\t"; +; +} +} +frame = frame.pop(); +output += "\n\t\t\t\t\n\t\t\t\n\t\t
    MedlemSlett
    "; +output += runtime.suppressValue(runtime.memberLookup((t_9),"forward", env.autoesc), env.autoesc); +output += "
    \n\t\t\t\t
    \n\t\t\t\t
    \n\t
    \n
    \n"; +; +} +} else { +t_1 = -1; +var t_2 = runtime.keys(t_3).length; +for(var t_10 in t_3) { +t_1++; +var t_11 = t_3[t_10]; +frame.set("list", t_10); +frame.set("members", t_11); +frame.set("loop.index", t_1 + 1); +frame.set("loop.index0", t_1); +frame.set("loop.revindex", t_2 - t_1); +frame.set("loop.revindex0", t_2 - t_1 - 1); +frame.set("loop.first", t_1 === 0); +frame.set("loop.last", t_1 === t_2 - 1); +frame.set("loop.length", t_2); +output += "\n
    \n\t
    \n\t
    "; +output += runtime.suppressValue(t_10, env.autoesc); +output += " "; +output += runtime.suppressValue(env.getFilter("length").call(context, t_11), env.autoesc); +output += "
    \n\t\t\n\t\t\t\n\t\t \n\t\t\t \n\t\t\t \n\t\t \n\t \n\t \n\t\t\t"; +frame = frame.push(); +var t_14 = t_11; +if(t_14) {var t_13 = t_14.length; +for(var t_12=0; t_12 < t_14.length; t_12++) { +var t_15 = t_14[t_12]; +frame.set("member", t_15); +frame.set("loop.index", t_12 + 1); +frame.set("loop.index0", t_12); +frame.set("loop.revindex", t_13 - t_12); +frame.set("loop.revindex0", t_13 - t_12 - 1); +frame.set("loop.first", t_12 === 0); +frame.set("loop.last", t_12 === t_13 - 1); +frame.set("loop.length", t_13); +output += "\n\t\t\t\t\n\t\t\t"; +; +} +} +frame = frame.pop(); +output += "\n\t\t\t\t\n\t\t\t\n\t\t
    MedlemSlett
    "; +output += runtime.suppressValue(runtime.memberLookup((t_15),"forward", env.autoesc), env.autoesc); +output += "
    \n\t\t\t\t
    \n\t\t\t\t
    \n\t
    \n
    \n"; +; +} +} +} +frame = frame.pop(); +cb(null, output); +; +} catch (e) { + cb(runtime.handleError(e, lineno, colno)); +} +} +return { +root: root +}; +})(); +})(); + +(function() {(window.nunjucksPrecompiled = window.nunjucksPrecompiled || {})["orgunits.html"] = (function() {function root(env, context, frame, runtime, cb) { +var lineno = null; +var colno = null; +var output = ""; +try { +frame = frame.push(); +var t_3 = runtime.contextOrFrameLookup(context, frame, "orgunits"); +if(t_3) {var t_2 = t_3.length; +for(var t_1=0; t_1 < t_3.length; t_1++) { +var t_4 = t_3[t_1]; +frame.set("ou", t_4); +frame.set("loop.index", t_1 + 1); +frame.set("loop.index0", t_1); +frame.set("loop.revindex", t_2 - t_1); +frame.set("loop.revindex0", t_2 - t_1 - 1); +frame.set("loop.first", t_1 === 0); +frame.set("loop.last", t_1 === t_2 - 1); +frame.set("loop.length", t_2); +output += "\n
  • "; +output += runtime.suppressValue(runtime.memberLookup((t_4),"name", env.autoesc), env.autoesc); +output += "
  • \n"; +; +} +} +frame = frame.pop(); +cb(null, output); +; +} catch (e) { + cb(runtime.handleError(e, lineno, colno)); +} +} +return { +root: root +}; +})(); +})(); diff --git a/mailadmin/static/dist/styles/main.css b/mailadmin/static/dist/styles/main.css index b9fbc65..6be519a 100644 --- a/mailadmin/static/dist/styles/main.css +++ b/mailadmin/static/dist/styles/main.css @@ -6515,3 +6515,50 @@ button.close { display: none !important; } } +.login-form { + margin: 0 auto; + max-width: 400px; + float: none; +} +.login-form input[type=submit] { + float: right; +} + +/* Hide for mobile, show later */ +.sidebar { + display: none; +} +@media (min-width: 768px) { + .sidebar { + display: block; + } +} + +/* Sidebar navigation */ +.nav-sidebar > .active > a, +.nav-sidebar > .active > a:hover, +.nav-sidebar > .active > a:focus { + color: #fff; + background-color: #428bca; +} + +/* Sticky footer styles */ +html { + position: relative; + min-height: 100%; +} + +body { + /* Margin bottom by footer height */ + margin-bottom: 60px; +} + +.footer { + position: absolute; + bottom: 0; + width: 100%; + /* Set the fixed height of the footer here */ + height: 60px; + background-color: #f5f5f5; + padding-top: 20px; +} diff --git a/mailadmin/static/dist/templates/list.js b/mailadmin/static/dist/templates/list.js index 7155583..bfd5073 100644 --- a/mailadmin/static/dist/templates/list.js +++ b/mailadmin/static/dist/templates/list.js @@ -20,7 +20,7 @@ frame.set("loop.revindex0", t_2 - t_1 - 1); frame.set("loop.first", t_1 === 0); frame.set("loop.last", t_1 === t_2 - 1); frame.set("loop.length", t_2); -output += "\n
    \n\t
    \n\t
    "; +output += "\n
    \n\t
    \n\t
    "; output += runtime.suppressValue(t_4, env.autoesc); output += " "; output += runtime.suppressValue(env.getFilter("length").call(context, t_5), env.autoesc); @@ -67,7 +67,7 @@ frame.set("loop.revindex0", t_2 - t_1 - 1); frame.set("loop.first", t_1 === 0); frame.set("loop.last", t_1 === t_2 - 1); frame.set("loop.length", t_2); -output += "\n
    \n\t
    \n\t
    "; +output += "\n
    \n\t
    \n\t
    "; output += runtime.suppressValue(t_10, env.autoesc); output += " "; output += runtime.suppressValue(env.getFilter("length").call(context, t_11), env.autoesc); diff --git a/mailadmin/static/gulpfile.js b/mailadmin/static/gulpfile.js index c5bb89a..cd42032 100644 --- a/mailadmin/static/gulpfile.js +++ b/mailadmin/static/gulpfile.js @@ -46,9 +46,10 @@ gulp.task('fonts', function () { .pipe($.size()); }); gulp.task('templates', function () { - return gulp.src('app/templates/list.html') + return gulp.src('app/templates/*.html') .pipe($.nunjucks()) - .pipe(gulp.dest('dist/templates')) + .pipe($.concat('templates.js')) + .pipe(gulp.dest('dist/scripts')) .pipe($.size()); }); @@ -90,4 +91,5 @@ gulp.task('watch', ['serve'], function () { gulp.watch('app/styles/**/*.scss', ['styles']); gulp.watch('app/scripts/**/*.js', ['scripts']); gulp.watch('app/images/**/*', ['images']); + gulp.watch('app/templates/**/*.html', ['templates']); }); diff --git a/mailadmin/static/package.json b/mailadmin/static/package.json index 0ab8eb3..190386e 100644 --- a/mailadmin/static/package.json +++ b/mailadmin/static/package.json @@ -10,6 +10,7 @@ "gulp-bower-files": "^0.2.1", "gulp-cache": "^0.1.11", "gulp-clean": "^0.2.4", + "gulp-concat": "^2.4.1", "gulp-csso": "^0.2.6", "gulp-filter": "^0.4.1", "gulp-flatten": "^0.0.2", diff --git a/mailadmin/templates/base.html b/mailadmin/templates/base.html index f53d92d..b4910b5 100644 --- a/mailadmin/templates/base.html +++ b/mailadmin/templates/base.html @@ -7,10 +7,16 @@ - + - + + {% include "nav.html" %} + {% block "navigation" %}{% endblock %} + {% block "body" %}{% endblock %} + + + \ No newline at end of file diff --git a/mailadmin/templates/home.html b/mailadmin/templates/home.html index 73ef35b..ef640a8 100644 --- a/mailadmin/templates/home.html +++ b/mailadmin/templates/home.html @@ -1,22 +1,29 @@ {% extends "base.html" %} -{% load bootstrap %} +{% block "body-css-classes" %}{% if user.is_authenticated %}home{% else %}login{% endif %}{% endblock %} {% block "body" %}
    - {% if not user.is_authenticated %} -
    - {{ form|bootstrap }} - {% csrf_token %} - -
    - {% else %} -
    Hei, {{ user.username }}
    - Logg ut. - {% endif %} + {% if not user.is_authenticated %} + {% include "login_form.html" %} + {% else %} +
    + +
    +
    +
    +
    + {% endif %}
    -
    -
    -
    - API
    +
    + +
    {% endblock %} \ No newline at end of file diff --git a/mailadmin/templates/login_form.html b/mailadmin/templates/login_form.html new file mode 100644 index 0000000..b187a59 --- /dev/null +++ b/mailadmin/templates/login_form.html @@ -0,0 +1,9 @@ +{% load bootstrap %} + \ No newline at end of file diff --git a/mailadmin/templates/nav.html b/mailadmin/templates/nav.html new file mode 100644 index 0000000..1329547 --- /dev/null +++ b/mailadmin/templates/nav.html @@ -0,0 +1,24 @@ + \ No newline at end of file diff --git a/mailadmin/urls.py b/mailadmin/urls.py index 9a510fe..61a0a77 100644 --- a/mailadmin/urls.py +++ b/mailadmin/urls.py @@ -1,12 +1,13 @@ from django.conf.urls import patterns, url from rest_framework.routers import DefaultRouter -from mailadmin.views import ForwardsViewSet, MyUserViewSet, OrgUnitViewSet, ForwardCreateView, ForwardDeleteView +from mailadmin.views import ForwardsViewSet, MyUserViewSet, MyOrgUnitViewSet, OrgUnitViewSet, ForwardCreateView, ForwardDeleteView router = DefaultRouter() router.register(r'forwards', ForwardsViewSet, base_name='all') router.register(r'me', MyUserViewSet, base_name='me') -router.register(r'orgunits', OrgUnitViewSet, base_name='ous') +router.register(r'orgunits', MyOrgUnitViewSet, base_name='ous') +router.register(r'orgunits/all', OrgUnitViewSet, base_name='allous') urlpatterns = router.urls urlpatterns += patterns( diff --git a/mailadmin/views.py b/mailadmin/views.py index 7fb68c3..700ecdd 100644 --- a/mailadmin/views.py +++ b/mailadmin/views.py @@ -114,7 +114,16 @@ class MyUserViewSet(viewsets.ReadOnlyModelViewSet): return User.objects.filter(pk=self.request.user.pk) +class MyOrgUnitViewSet(viewsets.ReadOnlyModelViewSet): + queryset = OrgUnit.objects.none() + serializer_class = OrgUnitSerializer + permission_classes = [IsAuthenticated] + + def get_queryset(self): + return OrgUnit.objects.filter(admin_groups__in=self.request.user.groups.values('id')) + + class OrgUnitViewSet(viewsets.ReadOnlyModelViewSet): queryset = OrgUnit.objects.all() serializer_class = OrgUnitSerializer - permission_classes = [IsAuthenticated] \ No newline at end of file + permission_classes = [IsAuthenticated] diff --git a/mailadminsite/urls.py b/mailadminsite/urls.py index 3afe3ff..c3b6b76 100644 --- a/mailadminsite/urls.py +++ b/mailadminsite/urls.py @@ -8,7 +8,7 @@ urlpatterns = patterns( url(r'^api/', include('mailadmin.urls')), url(r'^admin/', include(admin.site.urls)), url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')), - url(r'^/logout/$', 'django.contrib.auth.views.logout', name='logout') + url(r'^logout/$', 'django.contrib.auth.views.logout', name='logout') ) -urlpatterns += staticfiles_urlpatterns() \ No newline at end of file +urlpatterns += staticfiles_urlpatterns()