From 042b59bb791ebd8c514e734989cdf339e921a721 Mon Sep 17 00:00:00 2001 From: Michael Foiani Date: Fri, 6 Sep 2019 12:28:56 -0400 Subject: Added options to archive previous year's data --- src/actions/firebaseFirestore.js | 43 ++++++++++++++++++++++++++++++ src/components/mao-admin.js | 57 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 96 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/actions/firebaseFirestore.js b/src/actions/firebaseFirestore.js index 10e285a..c43a77f 100644 --- a/src/actions/firebaseFirestore.js +++ b/src/actions/firebaseFirestore.js @@ -228,3 +228,46 @@ export const createComment = (postId, content) => (dispatch, getState) => { } } +//TODO: Make it per year, not hard coded... + +export const archiveClass2019 = () => (dispatch, getState) => { + if(getState().app.offline) { + alert('Failed to archive class. Please establish internet connection.'); + } else { + var docRef = firestore.collection('users'); + docRef.get().then((oldUsers) => { + oldUsers.forEach((user) => { + var newPath = firestore.collection('archived').doc('2019').collection('users'); + newPath.doc(user.id).set(user.data()); + + if(user.data().username && user.data().username.includes('2019')) { + console.log(user.data().username, user.id); + docRef.doc(user.id).delete(); + } + + docRef.doc(user.id).update({hours: 0}); + + }); + }); + } +} + +export const archiveCompetitions2019 = () => (dispatch, getState) => { + if(getState().app.offline) { + alert('Failed to archive competitions. Please establish internet connection.'); + } else { + var docRef = firestore.collection('competitions'); + docRef.get().then((oldCompetitions) => { + oldCompetitions.forEach((comp) => { + console.log(comp.id, comp.data()); + var newPath = firestore.collection('archived').doc('2019').collection('competitions'); + newPath.doc(comp.id).set(comp.data()); + + //This will delete the document in its old place... + docRef.doc(comp.id).delete(); + + }); + }); + + } +} diff --git a/src/components/mao-admin.js b/src/components/mao-admin.js index 05357fc..19bf16e 100644 --- a/src/components/mao-admin.js +++ b/src/components/mao-admin.js @@ -17,7 +17,10 @@ import { store } from '../store.js'; // These are the shared styles needed by this element. import { SharedStyles } from './shared-styles.js'; -import { ButtonSharedStyles } from './button-shared-styles.js' +import { ButtonSharedStyles } from './button-shared-styles.js'; + +//These are the actions needed by this element. +import { archiveClass2019, archiveCompetitions2019 } from '../actions/firebaseFirestore.js'; // Import paper elements import '@polymer/paper-input/paper-input.js'; @@ -56,10 +59,36 @@ class MaoAdmin extends connect(store)(PageViewElement) { text-align: center; } + .white { + background-color: white; + + width: 50%; + + display: block; + margin-right: auto; + margin-left: auto; + } + + .search-grid { + display: grid; + + grid-template-columns: 1fr; + } + + .search-grid > paper-button { + display: grid; + + background-color: white; + } + @media (min-width: 460px) { .main-grid { grid-template-columns: 1fr 1fr 1fr; } + + .search-grid { + grid-template-columns: 3fr 1fr; + } } @@ -72,7 +101,7 @@ class MaoAdmin extends connect(store)(PageViewElement) {
Show Hours Requests - Show Competitions And Registry + Show Comps & Registry ${props.usersHidden ? 'Show User Data' : 'Hide User Data'}
@@ -89,6 +118,8 @@ class MaoAdmin extends connect(store)(PageViewElement) { @@ -101,8 +132,14 @@ class MaoAdmin extends connect(store)(PageViewElement) {