From 77d7d0af998f5ba8a7206b6c6b3a0110570fe831 Mon Sep 17 00:00:00 2001 From: Nikolai R Kristiansen Date: Sun, 5 Jan 2020 17:21:19 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20Cleanups?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove unused files - Remove usage of lodash, query-string and momentjs - Don't bundle svg and eot fonts from fontawesome --- mailadmin/static/mailadmin/gulpfile.js | 107 ---- mailadmin/static/mailadmin/package-lock.json | 31 +- mailadmin/static/mailadmin/package.json | 3 - .../static/mailadmin/src/_pnotify.core.scss | 112 ----- .../mailadmin/src/components/MainArea.js | 6 +- mailadmin/static/mailadmin/src/index.js | 1 - mailadmin/static/mailadmin/src/index.old.js | 461 ------------------ mailadmin/static/mailadmin/src/index.scss | 182 +------ .../src/{ => styles}/_animations.scss | 0 .../static/mailadmin/src/styles/_fonts.scss | 21 + .../static/mailadmin/src/styles/_footer.scss | 0 .../static/mailadmin/src/styles/_login.scss | 9 + .../mailadmin/src/styles/_mainarea.scss | 143 ++++++ .../mailadmin/src/{ => styles}/_sidebar.scss | 0 .../static/mailadmin/src/templates/alert.html | 4 - .../mailadmin/src/templates/aliases.html | 8 - .../static/mailadmin/src/templates/list.html | 30 -- .../mailadmin/src/templates/new_list.html | 23 - .../mailadmin/src/templates/orgunits.html | 4 - .../src/templates/orgunits_select.html | 6 - mailadmin/static/mailadmin/src/utils.js | 23 +- mailadmin/static/mailadmin/webpack.config.js | 6 +- 22 files changed, 204 insertions(+), 976 deletions(-) delete mode 100644 mailadmin/static/mailadmin/gulpfile.js delete mode 100644 mailadmin/static/mailadmin/src/_pnotify.core.scss delete mode 100644 mailadmin/static/mailadmin/src/index.old.js rename mailadmin/static/mailadmin/src/{ => styles}/_animations.scss (100%) create mode 100644 mailadmin/static/mailadmin/src/styles/_fonts.scss create mode 100644 mailadmin/static/mailadmin/src/styles/_footer.scss create mode 100644 mailadmin/static/mailadmin/src/styles/_login.scss create mode 100644 mailadmin/static/mailadmin/src/styles/_mainarea.scss rename mailadmin/static/mailadmin/src/{ => styles}/_sidebar.scss (100%) delete mode 100644 mailadmin/static/mailadmin/src/templates/alert.html delete mode 100644 mailadmin/static/mailadmin/src/templates/aliases.html delete mode 100644 mailadmin/static/mailadmin/src/templates/list.html delete mode 100644 mailadmin/static/mailadmin/src/templates/new_list.html delete mode 100644 mailadmin/static/mailadmin/src/templates/orgunits.html delete mode 100644 mailadmin/static/mailadmin/src/templates/orgunits_select.html diff --git a/mailadmin/static/mailadmin/gulpfile.js b/mailadmin/static/mailadmin/gulpfile.js deleted file mode 100644 index 9550b83..0000000 --- a/mailadmin/static/mailadmin/gulpfile.js +++ /dev/null @@ -1,107 +0,0 @@ -'use strict'; - -var gulp = require('gulp'); -var $ = require('gulp-load-plugins')(); -var del = require('del'); -var browserSync = require('browser-sync').create(); -var reload = browserSync.reload; - -gulp.task('styles', function () { - return gulp.src('app/styles/main.scss') - .pipe($.sass({ - includePaths: ['.'], - sourceComments: 'map' - }).on('error', $.sass.logError)) - - .pipe($.autoprefixer('last 1 version')) - .pipe(gulp.dest('dist/styles')) - .pipe(browserSync.stream()); -}); - -gulp.task('scripts', function () { - return gulp.src('app/scripts/**/*.js') - .pipe($.jshint()) - .pipe($.jshint.reporter(require('jshint-stylish'))) - .pipe(gulp.dest('dist/scripts')) -}); -gulp.task('vendorscripts', function() { - var vendorScripts = [ - 'node_modules/jquery/dist/jquery.min.js', - 'node_modules/underscore/underscore-min.js', - 'node_modules/nunjucks/browser/nunjucks-slim.min.js', - 'node_modules/moment/min/moment.min.js', - 'node_modules/moment/locale/nb.js', - 'node_modules/bootstrap-sass/assets/javascripts/bootstrap/alert.js', - 'node_modules/bootstrap-sass/assets/javascripts/bootstrap/dropdown.js', - 'node_modules/bootstrap-sass/assets/javascripts/bootstrap/collapse.js', - 'node_modules/pnotify/dist/pnotify.js', - 'node_modules/query-string/query-string.js' - ]; - return gulp.src(vendorScripts) - .pipe($.concat('vendor.js')) - .pipe(gulp.dest('dist/scripts')); -}); - -gulp.task('images', function () { - return gulp.src('app/images/**/*') - .pipe($.imagemin({ - optimizationLevel: 3, - progressive: true, - interlaced: true - })) - .pipe(gulp.dest('dist/images')) -}); - -gulp.task('fonts', function () { - return gulp.src(['node_modules/bootstrap-sass/assets/fonts/**/*']) - .pipe($.filter('**/*.{eot,svg,ttf,woff,woff2}')) - .pipe($.flatten()) - .pipe(gulp.dest('dist/fonts')) -}); -gulp.task('templates', function () { - return gulp.src('app/templates/*.html') - .pipe($.nunjucks()) - .pipe($.concat('templates.js')) - .pipe(gulp.dest('dist/scripts')) -}); - -gulp.task('extras', function () { - return gulp.src(['app/*.*', '!app/*.html', '!app/templates/*.html', '!app/styles/*.scss'], { dot: true }) - .pipe(gulp.dest('dist')); -}); - -gulp.task('clean', del.bind(null, ['dist'])); - -gulp.task('build', ['styles', 'scripts', 'vendorscripts', 'templates', 'images', 'fonts', 'extras'], - function() { - return gulp.src('dist/**/*').pipe($.size({title: 'build', gzip: true})); - } -); - -gulp.task('default', ['clean'], function () { - gulp.start('build'); -}); - -gulp.task('serve', ['styles', 'scripts'], function () { - require('opn')('http://localhost:3000'); -}); - - -gulp.task('watch', ['serve'], function () { - browserSync.init({ - proxy: 'localhost:8000' - }); - - // watch for changes - gulp.watch([ - '../../templates/**/*.html', - 'app/templates/*.html', - 'dist/scripts/**/*.js', - 'dist/images/**/*' - ]).on('change', reload); - - 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/mailadmin/package-lock.json b/mailadmin/static/mailadmin/package-lock.json index 6b0c323..949a253 100644 --- a/mailadmin/static/mailadmin/package-lock.json +++ b/mailadmin/static/mailadmin/package-lock.json @@ -3357,7 +3357,8 @@ "decode-uri-component": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/decode-uri-component/-/decode-uri-component-0.2.0.tgz", - "integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=" + "integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=", + "dev": true }, "deep-equal": { "version": "1.1.1", @@ -7289,7 +7290,8 @@ "lodash": { "version": "4.17.15", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", - "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" + "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==", + "dev": true }, "lodash.isfinite": { "version": "3.3.2", @@ -7684,11 +7686,6 @@ } } }, - "moment": { - "version": "2.24.0", - "resolved": "https://registry.npmjs.org/moment/-/moment-2.24.0.tgz", - "integrity": "sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==" - }, "move-concurrently": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/move-concurrently/-/move-concurrently-1.0.1.tgz", @@ -9603,16 +9600,6 @@ "resolved": "https://registry.npmjs.org/qs/-/qs-6.9.1.tgz", "integrity": "sha512-Cxm7/SS/y/Z3MHWSxXb8lIFqgqBowP5JMlTUFyJN88y0SGQhVmZnqFK/PeuMX9LzUyWsqqhNxIyg0jlzq946yA==" }, - "query-string": { - "version": "6.9.0", - "resolved": "https://registry.npmjs.org/query-string/-/query-string-6.9.0.tgz", - "integrity": "sha512-KG4bhCFYapExLsUHrFt+kQVEegF2agm4cpF/VNc6pZVthIfCc/GK8t8VyNIE3nyXG9DK3Tf2EGkxjR6/uRdYsA==", - "requires": { - "decode-uri-component": "^0.2.0", - "split-on-first": "^1.0.0", - "strict-uri-encode": "^2.0.0" - } - }, "querystring": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.0.tgz", @@ -11066,11 +11053,6 @@ } } }, - "split-on-first": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/split-on-first/-/split-on-first-1.1.0.tgz", - "integrity": "sha512-43ZssAJaMusuKWL8sKUBQXHWOpq8d6CfN/u1p4gUzfJkM05C8rxTmYrkIPTXapZpORA6LkkzcUulJ8FqA7Uudw==" - }, "split-string": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/split-string/-/split-string-3.1.0.tgz", @@ -11214,11 +11196,6 @@ "limiter": "^1.0.5" } }, - "strict-uri-encode": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/strict-uri-encode/-/strict-uri-encode-2.0.0.tgz", - "integrity": "sha1-ucczDHBChi9rFC3CdLvMWGbONUY=" - }, "string-width": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", diff --git a/mailadmin/static/mailadmin/package.json b/mailadmin/static/mailadmin/package.json index 9b640b7..e0c8f4a 100644 --- a/mailadmin/static/mailadmin/package.json +++ b/mailadmin/static/mailadmin/package.json @@ -23,12 +23,9 @@ "graphql-anywhere": "^4.2.6", "graphql-tag": "^2.10.1", "jquery": "^3.4.1", - "lodash": "^4.17.15", - "moment": "^2.24.0", "pnotify": "^4.0.0", "popper.js": "^1.16.0", "qs": "^6.9.1", - "query-string": "^6.9.0", "react": "^16.12.0", "react-dom": "^16.12.0" }, diff --git a/mailadmin/static/mailadmin/src/_pnotify.core.scss b/mailadmin/static/mailadmin/src/_pnotify.core.scss deleted file mode 100644 index c745a45..0000000 --- a/mailadmin/static/mailadmin/src/_pnotify.core.scss +++ /dev/null @@ -1,112 +0,0 @@ -/* -Author : Hunter Perrin -Version : 3.0.0 -Link : http://sciactive.com/pnotify/ -*/ -/* -- Notice */ -.ui-pnotify { - top: 36px; - right: 36px; - position: absolute; - height: auto; - z-index: 2; -} -body > .ui-pnotify { - /* Notices in the body context should be fixed to the viewport. */ - position: fixed; - /* Ensures notices are above everything */ - z-index: 100040; -} -.ui-pnotify-modal-overlay { - background-color: rgba(0, 0, 0, .4); - top: 0; - left: 0; - position: absolute; - height: 100%; - width: 100%; - z-index: 1; -} -body > .ui-pnotify-modal-overlay { - position: fixed; - z-index: 100039; -} -.ui-pnotify.ui-pnotify-in { - display: block !important; -} -.ui-pnotify.ui-pnotify-move { - transition: left .5s ease, top .5s ease, right .5s ease, bottom .5s ease; -} -.ui-pnotify.ui-pnotify-fade-slow { - transition: opacity .6s linear; - opacity: 0; -} -.ui-pnotify.ui-pnotify-fade-slow.ui-pnotify.ui-pnotify-move { - transition: opacity .6s linear, left .5s ease, top .5s ease, right .5s ease, bottom .5s ease; -} -.ui-pnotify.ui-pnotify-fade-normal { - transition: opacity .4s linear; - opacity: 0; -} -.ui-pnotify.ui-pnotify-fade-normal.ui-pnotify.ui-pnotify-move { - transition: opacity .4s linear, left .5s ease, top .5s ease, right .5s ease, bottom .5s ease; -} -.ui-pnotify.ui-pnotify-fade-fast { - transition: opacity .2s linear; - opacity: 0; -} -.ui-pnotify.ui-pnotify-fade-fast.ui-pnotify.ui-pnotify-move { - transition: opacity .2s linear, left .5s ease, top .5s ease, right .5s ease, bottom .5s ease; -} -.ui-pnotify.ui-pnotify-fade-in { - opacity: 1; -} -.ui-pnotify .ui-pnotify-shadow { - -webkit-box-shadow: 0px 6px 28px 0px rgba(0,0,0,0.1); - -moz-box-shadow: 0px 6px 28px 0px rgba(0,0,0,0.1); - box-shadow: 0px 6px 28px 0px rgba(0,0,0,0.1); -} -.ui-pnotify-container { - background-position: 0 0; - padding: .8em; - height: 100%; - margin: 0; -} -.ui-pnotify-container:after { - content: " "; /* Older browser do not support empty content */ - visibility: hidden; - display: block; - height: 0; - clear: both; -} -.ui-pnotify-container.ui-pnotify-sharp { - -webkit-border-radius: 0; - -moz-border-radius: 0; - border-radius: 0; -} -.ui-pnotify-title { - display: block; - margin-bottom: .4em; - margin-top: 0; -} -.ui-pnotify-text { - display: block; -} -.ui-pnotify-icon, .ui-pnotify-icon span { - display: block; - float: left; - margin-right: .2em; -} -/* Alternate stack initial positioning. */ -.ui-pnotify.stack-topleft, .ui-pnotify.stack-bottomleft { - left: 25px; - right: auto; -} -.ui-pnotify.stack-bottomright, .ui-pnotify.stack-bottomleft { - bottom: 25px; - top: auto; -} -.ui-pnotify.stack-modal { - left: 50%; - right: auto; - margin-left: -150px; -} diff --git a/mailadmin/static/mailadmin/src/components/MainArea.js b/mailadmin/static/mailadmin/src/components/MainArea.js index 4221fb5..1f41b75 100644 --- a/mailadmin/static/mailadmin/src/components/MainArea.js +++ b/mailadmin/static/mailadmin/src/components/MainArea.js @@ -1,10 +1,10 @@ import React from 'react'; -import { groupBy, sortBy } from 'lodash'; import { useQuery } from '@apollo/react-hooks'; import { GET_ALIASES, GET_DOMAINS } from '../queries'; import AliasList from './AliasList'; import AliasListCreate from './AliasListCreate'; +import { groupBy } from '../utils'; const MainArea = ({ query, selectedOrgUnit, orgUnits }) => { const { data, loading, error } = useQuery(GET_ALIASES); @@ -23,8 +23,8 @@ const MainArea = ({ query, selectedOrgUnit, orgUnits }) => { const domain = domainData.domains[0]; const lists = groupBy( - sortBy(data.aliases, (alias) => alias.source), - (alias) => alias.source + data.aliases.sort((a, b) => a.source.localeCompare(b.source)), + 'source' ); const listPrefixes = selectedOrgUnit && orgUnits.find(({ id }) => id === selectedOrgUnit).prefixesRegex; diff --git a/mailadmin/static/mailadmin/src/index.js b/mailadmin/static/mailadmin/src/index.js index 4722cea..b5053a4 100644 --- a/mailadmin/static/mailadmin/src/index.js +++ b/mailadmin/static/mailadmin/src/index.js @@ -6,7 +6,6 @@ import React from 'react'; import { render } from 'react-dom'; import './index.scss'; -import '@fortawesome/fontawesome-free/css/all.css'; import App from './App'; diff --git a/mailadmin/static/mailadmin/src/index.old.js b/mailadmin/static/mailadmin/src/index.old.js deleted file mode 100644 index d62d4ac..0000000 --- a/mailadmin/static/mailadmin/src/index.old.js +++ /dev/null @@ -1,461 +0,0 @@ -/* global moment, _, $, queryString, nunjucks, notify */ - -import { parseEmails, setQueryString } from './utils'; - -const API_URL = { - ALIASES: '/api/aliases/', - OU_LIST: '/api/orgunits/', - ME: '/api/me/', - EMAIL_DOMAIN: '/api/emaildomain/' -}; -let csrfToken; - -function filterLists(queryTerm, withMembers) { - const lists = $('.fwdlist').not('.new-list'); - if ($.trim(queryTerm) === '') { - $(lists) - .find('.alias-row') - .removeClass('highlight'); - $(lists).removeClass('hidden'); - return; - } - - /* Filter lists */ - const reTerm = new RegExp(queryTerm); - lists.each(function() { - const listName = $(this).attr('data-list-name'); - const members = $(this).find('.js-destination'); - let hits = 0; - if (withMembers) { - hits = _.filter(members, function(el) { - const matches = reTerm.test($(el).text()); - if (matches) { - $(el) - .parent() - .parent() - .addClass('highlight'); - } else { - $(el) - .parent() - .parent() - .removeClass('highlight'); - } - return matches; - }); - } else { - $('.alias-row').removeClass('highlight'); - } - - if (reTerm.test(listName) || (hits.length !== 0 && withMembers)) { - $(this).removeClass('hidden'); - } else { - $(this).addClass('hidden'); - } - }); -} - -function filterListsByOrgUnit(id, prefix) { - if (!prefix) { - prefix = $(`.orgunit-list a[data-id="${id}"]`).attr('data-prefix'); - } - // eslint-disable-next-line no-use-before-define - setActiveOrgUnit(id); - filterLists(prefix); - let queryParams = { orgunit: id }; - if (id === '') { - queryParams = null; - } - setQueryString(queryParams); -} - -function updateNumEmails(event) { - const el = $(event.target); - const emails = parseEmails(el.val()); - const listName = el.attr('data-list-name'); - const counter = $(`.fwdlist[data-list-name="${listName}"] .email-counter`); - - if (emails.length > 0) { - counter.text(emails.length); - } else { - counter.text(''); - } -} -function createAliases(newAliases, onSuccess, onError) { - $.ajax({ - url: API_URL.ALIASES, - type: 'POST', - headers: { 'X-CSRFToken': csrfToken }, - dataType: 'json', - contentType: 'application/json; charset=utf-8', - data: JSON.stringify(newAliases), - success: onSuccess, - error: onError - }); -} -function setActiveOrgUnit(id) { - /* Reset active */ - $('.orgunit-list li').removeClass('active'); - - /* Set current */ - const orgUnit = $(`.orgunit-list li a[data-id="${id}"]`); - orgUnit.parent().toggleClass('active'); - $('.orgunits-select').val(id); // - - -{% endfor %} \ No newline at end of file diff --git a/mailadmin/static/mailadmin/src/templates/list.html b/mailadmin/static/mailadmin/src/templates/list.html deleted file mode 100644 index d223274..0000000 --- a/mailadmin/static/mailadmin/src/templates/list.html +++ /dev/null @@ -1,30 +0,0 @@ -{% for list,aliases in lists %} -
-
-
{{ list }} {{aliases|length}}
- - - - {% include "aliases.html" %} - - - - - - - - - -
- Legg til - - Slett -
-

Eposter

- - -
-
-
-
-{% endfor %} \ No newline at end of file diff --git a/mailadmin/static/mailadmin/src/templates/new_list.html b/mailadmin/static/mailadmin/src/templates/new_list.html deleted file mode 100644 index cd87274..0000000 --- a/mailadmin/static/mailadmin/src/templates/new_list.html +++ /dev/null @@ -1,23 +0,0 @@ -
-
Ny liste
-
-
- - - - - - @{{email_domain.name}} -
-

Eposter

- - -
-
\ No newline at end of file diff --git a/mailadmin/static/mailadmin/src/templates/orgunits.html b/mailadmin/static/mailadmin/src/templates/orgunits.html deleted file mode 100644 index 5242f76..0000000 --- a/mailadmin/static/mailadmin/src/templates/orgunits.html +++ /dev/null @@ -1,4 +0,0 @@ -
  • Alle
  • -{% for ou in orgunits %} -
  • {{ ou.name }}
  • -{% endfor %} \ No newline at end of file diff --git a/mailadmin/static/mailadmin/src/templates/orgunits_select.html b/mailadmin/static/mailadmin/src/templates/orgunits_select.html deleted file mode 100644 index 92706f0..0000000 --- a/mailadmin/static/mailadmin/src/templates/orgunits_select.html +++ /dev/null @@ -1,6 +0,0 @@ - \ No newline at end of file diff --git a/mailadmin/static/mailadmin/src/utils.js b/mailadmin/static/mailadmin/src/utils.js index ac8b46e..7e6f7ab 100644 --- a/mailadmin/static/mailadmin/src/utils.js +++ b/mailadmin/static/mailadmin/src/utils.js @@ -1,6 +1,4 @@ import PNotify from 'pnotify/dist/es/PNotify'; -import PNotifyButtons from 'pnotify/dist/es/PNotifyButtons'; -import * as queryString from 'query-string'; export function parseEmails(text) { if (text === undefined || text === '') { @@ -24,11 +22,17 @@ export function parseEmails(text) { return [...new Set(emails)]; } +export const qsStringify = (obj) => { + const str = []; + for (const prop in obj) + if (obj.hasOwnProperty(prop)) { + str.push(`${encodeURIComponent(prop)}=${encodeURIComponent(obj[prop])}`); + } + return str.join('&'); +}; + export function setQueryString(obj) { - let qs = ''; - if (obj) { - qs = `?${queryString.stringify(obj)}`; - } + const qs = obj ? `?${qsStringify(obj)}` : ''; window.history.pushState(null, null, `/lists/${qs}`); } @@ -63,3 +67,10 @@ export function getCookie(name) { } return cookieValue; } + +export const groupBy = (xs, key) => { + return xs.reduce((rv, x) => { + (rv[x[key]] = rv[x[key]] || []).push(x); + return rv; + }, {}); +}; diff --git a/mailadmin/static/mailadmin/webpack.config.js b/mailadmin/static/mailadmin/webpack.config.js index 5c38aee..85447bc 100644 --- a/mailadmin/static/mailadmin/webpack.config.js +++ b/mailadmin/static/mailadmin/webpack.config.js @@ -19,11 +19,7 @@ module.exports = (env, argv) => { plugins: [ new MiniCssExtractPlugin(), env === 'production' ? new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/) : null, - env !== 'production' ? new HtmlWebpackPlugin({ template: './src/index.html' }) : null, - new webpack.ProvidePlugin({ - $: 'jquery', - _: 'lodash' - }) + env !== 'production' ? new HtmlWebpackPlugin({ template: './src/index.html' }) : null ].filter(Boolean), module: { rules: [