From 2aa1743e6c0b3d23c41c654fb7ba91906f029591 Mon Sep 17 00:00:00 2001 From: Yangguang Li Date: Mon, 1 Jul 2019 11:49:46 -0700 Subject: [PATCH] Admin users page. And some css fix --- static/elements/chromedash-userlist.js | 90 +++++++++++++++++++ static/js-src/schedule-page.js | 10 +-- static/sass/elements/chromedash-schedule.scss | 19 +--- static/sass/elements/chromedash-userlist.scss | 4 - static/sass/features/features.scss | 6 -- static/sass/samples.scss | 6 -- templates/_base.html | 2 +- templates/admin/blink.html | 14 +-- templates/admin/features/edit.html | 4 - templates/admin/features/launch.html | 4 - templates/admin/features/new.html | 4 - templates/admin/notifications/list.html | 2 +- templates/admin/subscribers.html | 12 +-- templates/admin/users/new.html | 15 ++-- templates/feature.html | 2 +- 15 files changed, 120 insertions(+), 74 deletions(-) diff --git a/static/elements/chromedash-userlist.js b/static/elements/chromedash-userlist.js index e69de29b..c0975c78 100644 --- a/static/elements/chromedash-userlist.js +++ b/static/elements/chromedash-userlist.js @@ -0,0 +1,90 @@ +import {LitElement, html} from 'https://unpkg.com/@polymer/lit-element@latest/lit-element.js?module'; + +class ChromedashUserlist extends LitElement { + static get properties() { + return { + actionPath: {type: String}, + users: {type: Array}, + }; + } + + constructor() { + super(); + this.users = []; + } + + addUser(user) { + this.users.splice(0, 0, user); + this.users = this.users.slice(0); // Refresh the list + } + + removeUser(idx) { + this.users.splice(idx, 1); + this.users = this.users.slice(0); // Refresh the list + } + + ajaxSubmit(e) { + e.preventDefault(); + const formEl = this.shadowRoot.querySelector('form'); + + if (formEl.checkValidity()) { + const email = formEl.querySelector('input[name="email"]').value; + const formData = new FormData(); + formData.append('email', email); + + fetch(this.actionPath, { + method: 'POST', + body: formData, + credentials: 'same-origin', // Needed for admin permissions to be sent. + }).then((resp) => { + if (resp.status === 200) { + alert('Thanks. But that user already exists'); + throw new Error('User already added'); + } else if (resp.status !== 201) { + throw new Error('Sever error adding new user'); + } + return resp.json(); + }).then((json) => { + this.addUser(json); + formEl.reset(); + }); + } + } + + ajaxDelete(e) { + e.preventDefault(); + if (!confirm('Remove user?')) { + return; + } + + const idx = e.target.dataset.index; + + fetch(e.currentTarget.href, { + method: 'POST', + credentials: 'same-origin', + }).then(() => { + this.removeUser(idx); + }); + } + + render() { + return html` + + +
+ + +
+ + `; + } +} + +customElements.define('chromedash-userlist', ChromedashUserlist); diff --git a/static/js-src/schedule-page.js b/static/js-src/schedule-page.js index 5cef51b7..1786dcab 100644 --- a/static/js-src/schedule-page.js +++ b/static/js-src/schedule-page.js @@ -8,12 +8,10 @@ document.querySelector('paper-toggle-button').addEventListener('change', e => { document.querySelector('chromedash-schedule').hideBlink = e.target.checked; }); -document.addEventListener('WebComponentsReady', function() { - const header = document.querySelector('app-header-layout app-header'); - if (header) { - header.fixed = false; - } -}); +const header = document.querySelector('app-header-layout app-header'); +if (header) { + header.fixed = false; +} async function init() { document.body.classList.remove('loading'); diff --git a/static/sass/elements/chromedash-schedule.scss b/static/sass/elements/chromedash-schedule.scss index d23bd3f3..4b3d61e7 100644 --- a/static/sass/elements/chromedash-schedule.scss +++ b/static/sass/elements/chromedash-schedule.scss @@ -4,7 +4,8 @@ :host { display: flex; flex-wrap: wrap; - padding-bottom: $content-padding * 5; + padding: 0 1em $content-padding * 5; + margin-right: $content-padding * -1; } iron-icon { @@ -76,15 +77,11 @@ iron-icon { padding: $content-padding; margin-bottom: $content-padding; border-radius: $default-border-radius; - flex: 1 0 calc(33.33% - 16px); - max-width: 33.33%; + flex: 1 0 0; min-width: 300px; + margin-right: $content-padding; counter-reset: featurecount; - &:not(:last-child) { - margin-right: $content-padding; - } - &.no-components { .feature_components { display: none; @@ -194,11 +191,3 @@ iron-icon { } } } - -@media only screen and (max-width: 700px) { - :host { - .release { - min-width: 100%; - } - } -} diff --git a/static/sass/elements/chromedash-userlist.scss b/static/sass/elements/chromedash-userlist.scss index dd6a9f46..d33c7e26 100644 --- a/static/sass/elements/chromedash-userlist.scss +++ b/static/sass/elements/chromedash-userlist.scss @@ -1,9 +1,5 @@ @import "element"; -:host { - display: block; -} - ul { margin-top: 10px; diff --git a/static/sass/features/features.scss b/static/sass/features/features.scss index 16fb86d9..fefc43e2 100644 --- a/static/sass/features/features.scss +++ b/static/sass/features/features.scss @@ -1,11 +1,5 @@ @import "../vars"; -/* Fix a bug. Left align the right side list and the header. - * TODO: Find out why it happens, and fix the root cause. */ -app-drawer-layout:not([narrow]) app-header-layout { - margin-left: -60px; -} - #content { // &.ready { // #spinner { diff --git a/static/sass/samples.scss b/static/sass/samples.scss index 37f41561..11f2961a 100644 --- a/static/sass/samples.scss +++ b/static/sass/samples.scss @@ -1,11 +1,5 @@ @import "vars"; -/* Fix a bug. Left align the right side list and the header. - * TODO: Find out why it happens, and fix the root cause. */ -app-drawer-layout:not([narrow]) app-header-layout { - margin-left: -60px; -} - paper-item { display: block; padding: 12px 16px; diff --git a/templates/_base.html b/templates/_base.html index d123a426..391185f4 100644 --- a/templates/_base.html +++ b/templates/_base.html @@ -42,7 +42,7 @@ limitations under the License. + {% endblock %} {% block drawer %} @@ -100,12 +102,12 @@ (function() { 'use strict'; -$('paper-toggle-button').addEventListener('change', e => { +document.querySelector('paper-toggle-button').addEventListener('change', e => { e.stopPropagation(); - $('#components_list').classList.toggle('editing', e.target.checked); + document.querySelector('#components_list').classList.toggle('editing', e.target.checked); }); -$('#components_list').addEventListener('click', function(e) { +document.querySelector('#components_list').addEventListener('click', function(e) { const addUser = e.target.classList.contains('add_owner_button'); const removeUser = e.target.classList.contains('remove_owner_button'); @@ -178,7 +180,7 @@ window.addEventListener('DOMContentLoaded', function(e) { if (location.hash) { setTimeout(function() { const el = document.getElementById(location.hash.slice(1)); - $('app-header').scroll(0, el.offsetTop); + document.querySelector('app-header').scroll(0, el.offsetTop); }, 500); } }); diff --git a/templates/admin/features/edit.html b/templates/admin/features/edit.html index 01bee93c..b3eed221 100644 --- a/templates/admin/features/edit.html +++ b/templates/admin/features/edit.html @@ -1,9 +1,5 @@ {% extends "_base.html" %} -{% block preload %} - -{% endblock %} - {% block css %} + {% endblock %} {% block drawer %} diff --git a/templates/admin/users/new.html b/templates/admin/users/new.html index 227399ea..ff6bfca2 100644 --- a/templates/admin/users/new.html +++ b/templates/admin/users/new.html @@ -1,12 +1,13 @@ {% extends "_base.html" %} {% block css %} - - + {% endblock %} {% block preload %} - + {% endblock %} {% block subheader %} @@ -25,11 +26,9 @@ {% block js %} {% endblock %} diff --git a/templates/feature.html b/templates/feature.html index 6e745237..e1eb994e 100644 --- a/templates/feature.html +++ b/templates/feature.html @@ -19,7 +19,7 @@ {% block preload %} {% endblock %}